Is there an event for after a product is saved only in admin?

All we need is an easy explanation of the problem, so here it is.

So I’m looking for an event for after a product is saved in the admin interface? Similar to catalog_product_prepare_save (which is before save).

It’s important that it doesn’t fire when e.g. another module does $product->save(). It should only fire when a someones saving a product manually using the admin interface.

Or any thoughts on other solutions of course.

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

There is no special event for saving the product from the admin interface, but you can use the general catalog_product_save_after and add a constraint to it based on the request.
Something like this:

public function catalogProductSaveAfter($observer) {
    if ($actionInstance = Mage::app()->getFrontController()->getAction()) {
        $action = $actionInstance->getFullActionName();
        if ($action == 'adminhtml_catalog_product_save') { //if on admin save action
            //do your magic here
        }
    }
}

Method 2

You could use controller_action_postdispatch_adminhtml_catalog_product_save, which is triggered after this action, but you should make sure that the product actually has been saved because the event will also be triggered if there was an error during save:

$product = Mage::registry('product');
if ($product && ! $product->hasDataChanges()) {

    // product has been saved

}

Explanation: _hasDataChanges is reset to false after a successful save.

Method 3

You can place catalog_product_save_after observer withing adminhtml tag of your module config.xml to make sure that will fire on product save from admin only

<?xml version="1.0"?>
<config>
    ...
    <adminhtml>
        ...
        <events>
            <catalog_product_save_after>
                <observers>
                    <product_save_after_observer>
                        <class>StackOverflow_CustomModule_Model_Observer</class>
                        <method>productSaveAfter</method>
                    </product_save_after_observer>
                </observers>
            </catalog_product_save_after>
        </events>
        ...
    </adminhtml>
    ...
</config>

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply