Reading list Switch to dark mode

    Save product in observer in magento 1

    Updated 11 December 2018

    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 🙂

    Searching for an experienced
    Magento Company ?
    Find out More
    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home