Is it possible to update product attributes without triggering reindex?
As known, the load()/setData()/save() scenario triggers reindex.
I've looked into 'updateAttributes' method in 'Mage_Catalog_Model_Product_Action' but I think it also triggers product reindex.
/**
* Update attribute values for entity list per store
*
* @param array $productIds
* @param array $attrData
* @param int $storeId
* @return Mage_Catalog_Model_Product_Action
*/
public function updateAttributes($productIds, $attrData, $storeId)
{
$this->_getResource()->updateAttributes($productIds, $attrData, $storeId);
$this->setData(array(
'product_ids' => array_unique($productIds),
'attributes_data' => $attrData,
'store_id' => $storeId
));
// register mass action indexer event
Mage::getSingleton('index/indexer')->processEntityAction(
$this, Mage_Catalog_Model_Product::ENTITY, Mage_Index_Model_Event::TYPE_MASS_ACTION
);
return $this;
}
The the code under '// register mass action indexer event' seems to trigger indexer action.
I found the way to update the attributes of a product without triggering reindex.
The main idea is the following: if you do update operations on the Model of the product, reindex is triggered, but if you do those operations on the Resource, that specific operation is done without reindex.
For example:
/**
* This method updates product attributes then triggers reindex
*/
Mage_Catalog_Model_Product_Action->updateAttributes($productIds, $attrData, $storeId);
/**
* This method updates product attributes but doesn't trigger reindex
*/
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Action->updateAttributes($productIds, $attrData, $storeId);
where:
$productIds
- an array with the products Ids $attrData
- an array having the keys as attribute name and values as attribute values$storeId
- store id of the product's assigned store (in case your product is assigned to multiple categories in different stores); If the attribute is global Mage_Core_Model_App::ADMIN_STORE_ID
can be used
Cheers!