Magento updates product attribute without reindex trigger

Can I update product attributes without running reindex?

As you know, the load () / setData () / save () script starts reindex.

I have studied the updateAttributes method in 'Mage_Catalog_Model_Product_Action', but I think it also launches the 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 code under the event index index "// bulk register" seems to trigger the action of the indexer.

+3
source share
2 answers

I found a way to update product attributes without running reindex.

The basic idea is this: if you perform update operations on a product model, then reindexing occurs, but if you perform these operations on a resource, this specific operation is performed without redefinition.

For instance:

/**
* 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 -
  • $attrData - ,
  • $storeId - , ( );

Mage_Core_Model_App::ADMIN_STORE_ID

!

+5

:

$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_MANUAL));
$processes->walk('save');

:

$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('reindexAll');
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_REAL_TIME));
$processes->walk('save');

: https://gist.github.com/2217520

, !

+5

All Articles