Request Quote

Save product in observer in magento 1

Save product in observer in magento 1

We cannot use save() to save product in observer in magento 1 if we are using event catalog_product_save_after because that will lead to an infinite loop.

So instead of using save(), we can save product data by using these lines of code-

$product = Mage::getModel('catalog/product')->load(1);
$price = 10;
$product->setData('price', $price);
$product->getResource()->saveAttribute($product, 'price');

In this manner we can save other attributes of a product as well, i.e, in place of price we can use sku, description etc.
Also, by saving a product in this manner will not trigger any events as well. That is why we can use it in event catalog_product_save_after
Happy coding 🙂

. . .


Add Your Comment

Be the first to comment.

Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again