[英]Observer Cancel order Magento
Hi I'm trying to add functionality when I'm canceling a order in Magento.嗨,当我在 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.在这种情况下,我entity_id
从我要取消的订单中获取entity_id
,但没有运气。 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.在 Magento 2.3 中有事件order_cancel_after
,它在取消发生后被调度。
The cancel
method in Magento\\Sales\\Model\\Order
looks like this: Magento\\Sales\\Model\\Order
的cancel
方法如下所示:
public function cancel()
{
if ($this->canCancel()) {
$this->getPayment()->cancel();
$this->registerCancellation();
$this->_eventManager->dispatch('order_cancel_after', ['order' => $this]);
}
return $this;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.