Here I have created a plugin to stop the order mail notification for some specific payment. This plugin is working fine on my localhost but not working on server.
My di.xml file codes:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Quote\Observer\SubmitObserver">
<plugin name="stop_order_email_for_some_payment" type="CompanyName\ModuleName\Plugin\Quote\Observer\SubmitObserver" sortOrder="0" />
</type>
</config>
And plugin file (CompanyName/ModuleName/Plugin/Quote/Observer/SubmitObserver.php) codes:
namespace CompanyName\ModuleName\Plugin\Quote\Observer;
class SubmitObserver
{
public function beforeExecute(
\Magento\Quote\Observer\SubmitObserver $subject,
\Magento\Framework\Event\Observer $observer
) {
/** @var \Magento\Sales\Model\Order $order */
$order = $observer->getEvent()->getOrder();
$paymentCode = $order->getPayment()->getMethodInstance()->getCode();
$orderStatus = $order->getStatus();
if($paymentCode == 'swed_m2s' || $paymentCode == 'seb_m2s' || $paymentCode == 'lhv_m2s' || $paymentCode == 'estcard_m2s' || $paymentCode == 'coop_m2s')
{
if($orderStatus == 'pending')
{
$order->setCanSendNewEmailFlag(false);
}
}
return [$observer];
}
}
On local System both column email_sent, send_email of sales_order table are updating with NULL value according to condition and also not getting order mail notification for selected payment methods which are checked in condition.
But on server neither columns are updating nor order mail notification is stopping.
Can anyone help me with this problem, why my plugin is not working on server.
Thanks!