Search code examples
eventsmagentostatusproduct

Magento "Product Status Update" event is not triggered


I'm working on an extension that will receive product information from Magento when saved and do custom processing on the product.

I've spent 2 days until now trying to figure out why Magento is not triggering the event "catalog_product_status_update".

Simply, I change product status by going to Catalog->Manage Products, then select one or more products and use the "Actions" field above the products grid to change product(s) status to "disabled".

When I do that, the product(s) status changes just fine, but the problem is that I don't receive the event for it. Here's the code I use:

<?xml version="1.0"?>
<config>
  <global>
    <models>
        <mage4ucustomredirect>
             <class>Mage4u_Customredirect</class>
        </mage4ucustomredirect>
    </models>
    <events>
       <catalog_product_save_after>
            <observers>
                <abc>
                    <type>singleton</type>
                    <class>Mage4u_Customredirect_Model_Observer</class>
                    <method>on_catalog_product_save_after</method>
                </abc>
            </observers>
       </catalog_product_save_after>
       <catalog_product_status_update>
            <observers>
                <abc>
                    <type>singleton</type>
                    <class>Mage4u_Customredirect_Model_Observer</class>
                    <method>on_catalog_product_status_update</method>
                </abc>
            </observers>
       </catalog_product_status_update>
    </events>
  </global>
</config>

And this is the observer:

class Mage4u_Customredirect_Model_Observer
{
    public function on_catalog_product_status_update(Varien_Event_Observer $observer)
    {  
        Mage::log( "on_catalog_product_status_update" );
    }

    public function on_catalog_product_save_after(Varien_Event_Observer $observer)
    {  
        Mage::log( "on_catalog_product_save_after"  );
    }
}
?>

Strange enough, when I try to save a product manually, I receive the event "on_catalog_product_save_after" which tells me that my code is working fine, but it doesn't work for this "on_catalog_product_status_update" event.

Any help is appreciated!

NOTE: I'm using Magento v1.6.2.0


Solution

  • I believe your problem is that the update status option at the top of the grid doesn't use any models to achieve the task, it access the database directly. If you look at the updateAttributes method in Mage_Catalog_Model_Product_Action and Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Action respectively, you will see that no product or product_status model is loaded.

    Unfortunately for you, at a quick glance I don't see any events that you can hook into to capture this. It might require rewriting of the model.