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_Catalog
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: * Catalog Product Mass Action processing model
30: *
31: * @category Mage
32: * @package Mage_Catalog
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Catalog_Model_Product_Action extends Mage_Core_Model_Abstract
36: {
37: /**
38: * Initialize resource model
39: *
40: */
41: protected function _construct()
42: {
43: $this->_init('catalog/product_action');
44: }
45:
46: /**
47: * Retrieve resource instance wrapper
48: *
49: * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Action
50: */
51: protected function _getResource()
52: {
53: return parent::_getResource();
54: }
55:
56: /**
57: * Update attribute values for entity list per store
58: *
59: * @param array $productIds
60: * @param array $attrData
61: * @param int $storeId
62: * @return Mage_Catalog_Model_Product_Action
63: */
64: public function updateAttributes($productIds, $attrData, $storeId)
65: {
66: Mage::dispatchEvent('catalog_product_attribute_update_before', array(
67: 'attributes_data' => &$attrData,
68: 'product_ids' => &$productIds,
69: 'store_id' => &$storeId
70: ));
71:
72: $this->_getResource()->updateAttributes($productIds, $attrData, $storeId);
73: $this->setData(array(
74: 'product_ids' => array_unique($productIds),
75: 'attributes_data' => $attrData,
76: 'store_id' => $storeId
77: ));
78:
79: // register mass action indexer event
80: Mage::getSingleton('index/indexer')->processEntityAction(
81: $this, Mage_Catalog_Model_Product::ENTITY, Mage_Index_Model_Event::TYPE_MASS_ACTION
82: );
83: return $this;
84: }
85:
86: /**
87: * Update websites for product action
88: *
89: * allowed types:
90: * - add
91: * - remove
92: *
93: * @param array $productIds
94: * @param array $websiteIds
95: * @param string $type
96: */
97: public function updateWebsites($productIds, $websiteIds, $type)
98: {
99: Mage::dispatchEvent('catalog_product_website_update_before', array(
100: 'website_ids' => $websiteIds,
101: 'product_ids' => $productIds,
102: 'action' => $type
103: ));
104:
105: if ($type == 'add') {
106: Mage::getModel('catalog/product_website')->addProducts($websiteIds, $productIds);
107: } else if ($type == 'remove') {
108: Mage::getModel('catalog/product_website')->removeProducts($websiteIds, $productIds);
109: }
110:
111: $this->setData(array(
112: 'product_ids' => array_unique($productIds),
113: 'website_ids' => $websiteIds,
114: 'action_type' => $type
115: ));
116:
117: // register mass action indexer event
118: Mage::getSingleton('index/indexer')->processEntityAction(
119: $this, Mage_Catalog_Model_Product::ENTITY, Mage_Index_Model_Event::TYPE_MASS_ACTION
120: );
121:
122: // add back compatibility system event
123: Mage::dispatchEvent('catalog_product_website_update', array(
124: 'website_ids' => $websiteIds,
125: 'product_ids' => $productIds,
126: 'action' => $type
127: ));
128: }
129: }
130: