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 processing resource model
30: *
31: * @category Mage
32: * @package Mage_Catalog
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Catalog_Model_Resource_Product_Action extends Mage_Catalog_Model_Resource_Abstract
36: {
37: /**
38: * Intialize connection
39: *
40: */
41: protected function _construct()
42: {
43: $resource = Mage::getSingleton('core/resource');
44: $this->setType(Mage_Catalog_Model_Product::ENTITY)
45: ->setConnection(
46: $resource->getConnection('catalog_read'),
47: $resource->getConnection('catalog_write')
48: );
49: }
50:
51: /**
52: * Update attribute values for entity list per store
53: *
54: * @param array $entityIds
55: * @param array $attrData
56: * @param int $storeId
57: * @return Mage_Catalog_Model_Resource_Product_Action
58: */
59: public function updateAttributes($entityIds, $attrData, $storeId)
60: {
61: $object = new Varien_Object();
62: $object->setIdFieldName('entity_id')
63: ->setStoreId($storeId);
64:
65: $this->_getWriteAdapter()->beginTransaction();
66: try {
67: foreach ($attrData as $attrCode => $value) {
68: $attribute = $this->getAttribute($attrCode);
69: if (!$attribute->getAttributeId()) {
70: continue;
71: }
72:
73: $i = 0;
74: foreach ($entityIds as $entityId) {
75: $i++;
76: $object->setId($entityId);
77: // collect data for save
78: $this->_saveAttributeValue($object, $attribute, $value);
79: // save collected data every 1000 rows
80: if ($i % 1000 == 0) {
81: $this->_processAttributeValues();
82: }
83: }
84: $this->_processAttributeValues();
85: }
86: $this->_getWriteAdapter()->commit();
87: } catch (Exception $e) {
88: $this->_getWriteAdapter()->rollBack();
89: throw $e;
90: }
91:
92: return $this;
93: }
94: }
95: