1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Adminhtml
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * Adminhtml catalog product action attribute update helper
30: *
31: * @category Mage
32: * @package Mage_Adminhtml
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Adminhtml_Helper_Catalog_Product_Edit_Action_Attribute extends Mage_Core_Helper_Data
36: {
37: /**
38: * Selected products for mass-update
39: *
40: * @var Mage_Catalog_Model_Entity_Product_Collection
41: */
42: protected $_products;
43:
44: /**
45: * Array of same attributes for selected products
46: *
47: * @var Mage_Eav_Model_Mysql4_Entity_Attribute_Collection
48: */
49: protected $_attributes;
50:
51: /**
52: * Excluded from batch update attribute codes
53: *
54: * @var array
55: */
56: protected $_excludedAttributes = array('url_key');
57:
58: /**
59: * Return product collection with selected product filter
60: * Product collection didn't load
61: *
62: * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
63: */
64: public function getProducts()
65: {
66: if (is_null($this->_products)) {
67: $productsIds = $this->getProductIds();
68:
69: if (!is_array($productsIds)) {
70: $productsIds = array(0);
71: }
72:
73: $this->_products = Mage::getResourceModel('catalog/product_collection')
74: ->setStoreId($this->getSelectedStoreId())
75: ->addIdFilter($productsIds);
76: }
77:
78: return $this->_products;
79: }
80:
81: /**
82: * Return array of selected product ids from post or session
83: *
84: * @return array|null
85: */
86: public function getProductIds()
87: {
88: $session = Mage::getSingleton('adminhtml/session');
89:
90: if ($this->_getRequest()->isPost() && $this->_getRequest()->getActionName() == 'edit') {
91: $session->setProductIds($this->_getRequest()->getParam('product', null));
92: }
93:
94: return $session->getProductIds();
95: }
96:
97: /**
98: * Return selected store id from request
99: *
100: * @return integer
101: */
102: public function getSelectedStoreId()
103: {
104: return (int)$this->_getRequest()->getParam('store', Mage_Core_Model_App::ADMIN_STORE_ID);
105: }
106:
107: /**
108: * Return array of attribute sets by selected products
109: *
110: * @return array
111: */
112: public function getProductsSetIds()
113: {
114: return $this->getProducts()->getSetIds();
115: }
116:
117: /**
118: * Return collection of same attributes for selected products without unique
119: *
120: * @return Mage_Eav_Model_Mysql4_Entity_Attribute_Collection
121: */
122: public function getAttributes()
123: {
124: if (is_null($this->_attributes)) {
125: $this->_attributes = Mage::getSingleton('eav/config')
126: ->getEntityType(Mage_Catalog_Model_Product::ENTITY)
127: ->getAttributeCollection()
128: ->addIsNotUniqueFilter()
129: ->setInAllAttributeSetsFilter($this->getProductsSetIds());
130:
131: if ($this->_excludedAttributes) {
132: $this->_attributes->addFieldToFilter('attribute_code', array('nin' => $this->_excludedAttributes));
133: }
134:
135: // check product type apply to limitation and remove attributes that impossible to change in mass-update
136: $productTypeIds = $this->getProducts()->getProductTypeIds();
137: foreach ($this->_attributes as $attribute) {
138: /* @var $attribute Mage_Catalog_Model_Entity_Attribute */
139: foreach ($productTypeIds as $productTypeId) {
140: $applyTo = $attribute->getApplyTo();
141: if (count($applyTo) > 0 && !in_array($productTypeId, $applyTo)) {
142: $this->_attributes->removeItemByKey($attribute->getId());
143: break;
144: }
145: }
146: }
147: }
148:
149: return $this->_attributes;
150: }
151:
152: /**
153: * Return product ids that not available for selected store
154: *
155: * @deprecated since 1.4.1
156: * @return array
157: */
158: public function getProductsNotInStoreIds()
159: {
160: return array();
161: }
162: }
163: