I've noticed in a couple community extensions we have installed that they observe the event catalog_product_save_after, and in the triggered method they will get the product and do something to it (add additional custom attribute data or whatever) and then save it.




public function saveProductData(Varien_Event_Observer $observer)
    $product = $observer->getEvent()->getProduct();
    try {
        $blocks = $this->_getRequest()->getPost('content_blocks');
        $product->setData('content_blocks', $content_blocks_value);
    } catch(Exception $e) {

This seems like it would cause some kind of infinite product save event triggering.. although it doesn't seem to be the case; using a debug/log statement I can see when saving a product it gets saved several times but not infinitely.

My question is, is this bad practice, and should these extensions not have passed Magento's extension marketplace Quality Assurance? If it is, what would be the proper way to implement?

1 Answer 1


This is no bad practice :)

The problem is this piece of code $product->save();.

The observer method is correct, but with this line catalog_product_save_after is triggered again, and again ... resulting in an infinite loop :)

Just as a note ... if you want to set data to the product catalog_product_save_before could fit better.

Edit: if you want to set an attribute value on save action, i'd use catalog_product_save_before:

public function saveProductData(Varien_Event_Observer $observer)
    $product = $observer->getProduct();
    $value = /* your code here */
    $product->setData('your_attribute_code', $value);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.