Return to Snippet

Revision: 49408
at July 21, 2011 19:29 by necode


Initial Code
config.xml
<global>
    <events>
        <customer_address_save_before>
            <observers>
                <yourmodule>
                    <type>singleton</type>
                    <class>yourmodule/observer</class>
                    <method>customer_address_save_before</method>
                </yourmodule>
            </observers>
        </customer_address_save_before>
 
        <customer_address_save_after>
            <observers>
                <yourmodule>
                    <type>singleton</type>
                    <class>yourmodule/observer</class>
                    <method>customer_address_save_after</method>
                </yourmodule>
            </observers>
        </customer_address_save_after>
 
        <catalog_product_save_before>
            <observers>
                <yourmodule>
                    <type>singleton</type>
                    <class>yourmodule/observer</class>
                    <method>catalog_product_save_before</method>
                </yourmodule>
            </observers>
        </catalog_product_save_before>
 
        <catalog_product_save_after>
            <observers>
                <yourmodule>
                    <type>singleton</type>
                    <class>yourmodule/observer</class>
                    <method>catalog_product_save_after</method>
                </yourmodule>
            </observers>
        </catalog_product_save_after>
    </events>
</global>

Observer.php
class YourNamespace_YourModule_Model_Observer
{
    public function customer_address_save_before($observer)
    {
        $address = $observer->getCustomerAddress();
        //echo "<pre>"; print_r($address->getData()); exit;
        // do something here
    }
 
    public function customer_address_save_after($observer)
    {
        $address = $observer->getCustomerAddress();
        //echo "<pre>"; print_r($address->getData()); exit;
        // do something here
    }
 
    public function catalog_product_save_before($observer)
    {
        $product = $observer->getProduct();
        //echo "<pre>"; print_r($product->getData()); exit;
        // do something here
    }
 
    public function catalog_product_save_after($observer)
    {
        $product = $observer->getProduct();
        //echo "<pre>"; print_r($product->getData()); exit;
        // do something here
    }
}

Initial URL
http://blog.chapagain.com.np/magento-event-observer-with-save-before-and-save-after/

Initial Description
http://codemagento.com/2011/04/observers-and-dispatching-events/

Initial Title
Magento Event Observer with Save before and Save after

Initial Tags
event, magento

Initial Language
PHP