Magento update product attribute without trigger reindex

Magento update product attribute without trigger reindex
Create a file updateAttribute.php on the root directory of your project folder and paste the the below code on your newly created (updateAttribute.php) file.

require_once('app/Mage.php'); 
umask(0);
Mage::app('admin');
// $product_id thhis is your product id(entity_id)
// $attribue_code this is your product attribute code (LIKE magento1 default code staus,description, etc )
// $value this is product code value 

FIRST WAY:- 
$product = Mage::getModel('catalog/product')->load($product_id); 
$resource = $product->getResource();
$product->setData($attribue_code, $value);
$resource->saveAttribute($product, $attribute_code);

SECOND WAY:-


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

Second run your product attribute code ..


NOTE:- if you run below code then reindex event will be trigger manually.. 
Third run below code.

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

Below is the example how to run the code..




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

$product = Mage::getModel('catalog/product')->load($product_id); 
$resource = $product->getResource();
$product->setData($attribue_code, $value);
$resource->saveAttribute($product, $attribute_code);

Leave a Reply