Magento 2 has many templates to send when the customer changes the order process like an invoice, shipment, credit memo, etc. But the same isn’t available on the cancellation process.
Today, we’re going to show you how to set it up for the cancelation process.
Module name: Magemonkeys_Cancelledorder
Create events.xml at app/code/Magemonkeys/Cancelledorder/etc/
1 2 3 4 5 6 7 8 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="sales_order_save_after"> <observer name="sales_order_save_after" instance="Magemonkeys\Cancelledorder\Observer\OrderSaveAfter"/> </event> </config> |
Then Create OrderSaveAfter.php at app/code/Magemonkeys/Cancelledorder/Observer/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?php namespace Magemonkeys\Cancelledorder\Observer; use Magento\Framework\Event\ObserverInterface; use Magento\Sales\Model\Order\Email\Sender\OrderCommentSender; class OrderSaveAfter implements ObserverInterface { protected $orderCommentSender; public function __construct( OrderCommentSender $orderCommentSender ) { $this->orderCommentSender = $orderCommentSender; } public function execute(\Magento\Framework\Event\Observer $observer) { $order = $observer->getEvent()->getOrder(); if ($order->getState() == 'canceled') { $this->orderCommentSender->send($order, true); } } } |
The mail will look something like the below.
Hope that helps.
If you want get query string params in controller file,...
Create di.xml and add the below code Magemonkey/Redirect/etc/frontend/di.xml [crayon-6286708e0cfdb958739032/] Create...
You can try below code to change local date to...
Step 1: First you need to add registration.php file in...
Step1 : Override message.js in current theme file on the...