Magento 2中不同类型的订单取消事件大赏

在Magento 2中有很多可用的事件,一些付款,发票或订单取消操作的事件如下,

1. order_cancel_after

取消订单后将使用此事件。如果您想在取消订单后做某事,可以使用此事件。

代码在 vendor/magento/module-sales/Model/Order.php at cancel() function.

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

2. sales_order_invoice_cancel

允许您在取消订单时取消订单发票

代码在vendor/magento/module-sales/Model/Order/Invoice.php at cancel() function.

$this->_eventManager->dispatch('sales_order_invoice_cancel', [$this->_eventObject => $this]);

3. sales_order_payment_cancel_invoice

允许您在取消订单时取消订单发票

代码在vendor/magento/module-sales/Model/Order/Invoice.php at cancel() function.

$this->_eventManager->dispatch('sales_order_invoice_cancel', [$this->_eventObject => $this]);

4. sales_order_payment_cancel_creditmemo

代码在vendor/magento/module-sales/Model/Order/Payment.php using cancelCreditmemo() function

$this->_eventManager->dispatch(
            'sales_order_payment_cancel_creditmemo',
            ['payment' => $this, 'creditmemo' => $creditmemo]
        );

5.sales_order_payment_cancel_invoice

从订单中取消指定的发票,并从订单发票中更新总计

代码在vendor/magento/module-sales/Model/Order/Payment.php

$this->_eventManager->dispatch(
            'sales_order_payment_cancel_invoice',
            ['payment' => $this, 'invoice' => $invoice]
        );

此事件包含付款和发票对象。

6. sales_order_creditmemo_cancel

当你想从一个特定的顺序或特定的物品退还订单
你最适合的事件是,sales_order_creditmemo_cancel

$this->eventManager->dispatch('sales_order_creditmemo_cancel', ['creditmemo' => $creditmemo]);

发表评论