Quantcast
Channel: Webkul Blog
Viewing all articles
Browse latest Browse all 5556

Save product in observer in magento 1

$
0
0

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 🙂


Viewing all articles
Browse latest Browse all 5556

Latest Images

Trending Articles



Latest Images