6

I am trying to do something customization from my custom module after an order has been cancelled (Frontend as well Backend). For this I have gone through cancelled Observer on the sales/etc/events.xml and sales/etc/adminhtml/events.xml, But I can't find where it is.

Could you please help me where it is(Observer)? to do something after cancelled the order Frontend(Customer) and Backend(Vendor/Seller).

Which observer will use from frontend and backend?

2 Answers 2

15

The event you're looking for is order_cancel_after and it's dispatched in the cancel method of \Magento\Sales\Model\Order :

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

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

    return $this;
}
3
  • How to send mail using above event? Its default not sending mail for order cancel Commented Mar 12, 2018 at 13:41
  • @RakeshJesadiya; were you able to send Order Cancel email using the event order_cancel_after? Commented Oct 11, 2018 at 15:02
  • I am unable to call the event order_cancel_after when a customer or an admin cancels an order? It seems this event is not being called when order is cancelled either from store front or admin Commented Oct 18, 2018 at 17:38
2

six types of Cancel events for Orders in Magento 2

1. order_cancel_after

This event is used after order canceled. If you want to do something after an order is canceled you can use this event. Check file, vendor/magento/module-sales/Model/Order.php at cancel() function.

2. sales_order_invoice_cancel

Allows you to cancel the order invoice when you canceled the order. Check event called at, file, vendor/magento/module-sales/Model/Order/Invoice.php at cancel() function.

3. sales_order_payment_cancel_invoice

Allows you to cancel the order invoice when you canceled the order. Check event called at, file, vendor/magento/module-sales/Model/Order/Invoice.php at cancel() function.

4. sales_order_payment_cancel_creditmemo

Event defined under vendor/magento/module-sales/Model/Order/Payment.php using cancelCreditmemo() function but this function is not called at any file. Might be used in future developments. This event contains payment and specified creditmemo object.

5. sales_order_payment_cancel_invoice

Cancel specified invoice from order and update self-total from order invoice. Event defined under vendor/magento/module-sales/Model/Order/Payment.php

6. sales_order_creditmemo_cancel

When you want to refund from a specific order or specific item from order, Your best suitable event is, sales_order_creditmemo_cancel

More detail you can review rakesh sir blog https://www.rakeshjesadiya.com/different-types-of-cancel-events-for-orders-in-magento-2/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.