Magento 1.4 Event Observer – How to Set After saveOrderAction

event-observermagento-1.4onepage-checkout

We use Onepage checkout in Magento 1.4

The file where the work is done is:

/app/code/core/Mage/Checkout/controllers/OnepageController.php

The function is saveOrderAction()

I want to perform an action after the order has been saved, but a) I don't see any dispatchEvent call in this function and b) I don't know which event to use or to search for.

I have seen exhaustive event lists for Mage 1.x, but I don't know how to correlate to this method.

I also need to know how to add the <observer> XML and place the function, as I have never done this before.

Best Answer

Hi you can use sales_order_place_after event.you need to define below code in your module config.xml.

 <global>
     <events>
        <sales_order_place_after>
            <observers>
                <OBSERVER_NAME>
                    <class>MODULE_FRONTNAME/NAME_OF_FILE_IN_MODEL_FOLDER</class>
                    <method>FUNCTION_NAME_FROM_ABOVE_CLASS</method>
                </OBSERVER_NAME>
            </observers>
        </sales_order_place_after>
     </events>
 </global>

If you need to define file under following path: app/code/YOUR_CODEPOOL/NAMESPACE/YOUR_MODULE/Model/NAME_OF_FILE_IN_MODEL_FOLDER.php Like Observer.php

In above file need to create function in observer.php with name which define in tag of config.xml:

<?php
    public function sales_order_afterPlace($observer)
    {
      $order = $observer->getEvent()->getOrder();
      /*YOUR LOGIC*/
    }
?>

I hope this will help you.