Search code examples
phpmagentoevents

Observer Cancel order Magento


Hi I'm trying to add functionality when I'm canceling a order in Magento. my config is working and when I'm cancelling a order my function gets triggered but i don't get the order dispatched to the observer. Here are the initial code of my class.

class Imo_Model_Observer {

    static function exportOrder($observer)
    {
        $order= $observer->getData('entity_id');

        self::createFile($order, 'completed');
        //echo "export started";
    }   

In this case i have tryed to get entity_id from the order I'm canceling but with no luck. i would like to get the whole order.


Solution

  • Cancelling a order means actually that order state is set to "cancelled" so you need to observe the event sales_order_save_after and get the order object from event, check which was the previous state and set your own state