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.
config.xml
<events>
<catalog_product_save_after>
<observers>
<foo_bar>
<type>singleton</type>
<class>foo_bar/observer</class>
<method>saveProductData</method>
</foo_bar>
</observers>
</catalog_product_save_after>
</events>
Observer.php
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);
$product->save();
} catch(Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
}
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?