简体   繁体   中英

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.

取消订单实际上意味着订单状态设置为“已取消”,因此您需要观察事件 sales_order_save_after 并从事件中获取订单对象,检查哪个是之前的状态并设置您自己的状态

Here is what i ended up with

  public function exportOrder(Varien_Event_Observer $observer)
   {
        $track = $observer->getEvent()->getPayment();
        $increment_id = $track->getOrder();

In Magento 2.3 there is the event order_cancel_after , which is dispatched after the cancellation took place.

The cancel method in Magento\\Sales\\Model\\Order looks like this:

public function cancel()
{
    if ($this->canCancel()) {
        $this->getPayment()->cancel();
        $this->registerCancellation();

        $this->_eventManager->dispatch('order_cancel_after', ['order' => $this]);
    }

    return $this;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM