Friday, 25 April 2014

Dispatch event and Observer in magento


Dispatch event and Observer in magento

If you want to override magento Core functionality , You should use dispatch event. Magento gives us facility of dispatch event and this is called one type of Hook.

Here is the syntax of dispatch event :
Mage::dispatchEvent('event_name', array('data' => $data));

In this event we use $observer variable, Suppose we want to save order data into
other database or other table so what we do for that. Magento has a default
dispatch event named "checkout_submit_all_after". Now create one module to
override the code...

Put below code in your module confix.xml file

<global>
<events>
    <checkout_submit_all_after>
         <observers>
              <chand_phpcoder_model_observer>
                   <type>singleton</type>
                   <class>Chand_Phpcoder_Model_Observer</class>
                   <method>saveOrder</method>
              </chand_phpcoder_model_observer>
         </observers>
    </checkout_submit_all_after>
</events>
</global>
Now open your Model and put Observer.php file and write below code :
<?php
class Chand_Phpcoder_Model_Observer {
    public function saveOrder($observer)
    {
      Mage::log('Your Statement');
    }
}
?>
That's it... Enjoy Chandresh rana's Coding.... :)
<global>
<global> <events> <checkout_submit_all_after> <observers> <awesome_example> <type>singleton</type> <class>awesome/observer</class> <method>doSomething</method> </awesome_example> </observers> </checkout_submit_all_after> </events> </global> - See more at: http://www.apptha.com/blog/magento-observers-and-dispatching-events-explained-explicitly/#sthash.fKW04nJx.dpuf
<global> <events> <checkout_submit_all_after> <observers> <awesome_example> <type>singleton</type> <class>awesome/observer</class> <method>doSomething</method> </awesome_example> </observers> </checkout_submit_all_after> </events> </global> - See more at: http://www.apptha.com/blog/magento-observers-and-dispatching-events-explained-explicitly/#sthash.fKW04nJx.dpuf
<global> <events> <checkout_submit_all_after> <observers> <awesome_example> <type>singleton</type> <class>awesome/observer</class> <method>doSomething</method> </awesome_example> </observers> </checkout_submit_all_after> </events> </global> - See more at: http://www.apptha.com/blog/magento-observers-and-dispatching-events-explained-explicitly/#sthash.fKW04nJx.dpuf

No comments: