I created a new template var using email_order_set_template_vars_before
observer and it works when I send email new order through the Magento admin. But it does not trigger when new order is placed. Here is my code.
events.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="email_order_set_template_vars_before">
<!-- <observer name="shipperhq_save_email_variables" disabled="true"/> -->
<observer name="cd_shipperhq_save_email_variables" instance="Foobar\ShipperHQDeliveryDate\Observer\SaveEmailVariables"/>
</event>
</config>
SaveEmailVariables.php
namespace Foobar\ShipperHQDeliveryDate\Observer;
use Magento\Framework\Event\ObserverInterface;
class SaveEmailVariables implements ObserverInterface
{
private $carrierGroupHelper;
public function __construct(\ShipperHQ\Shipper\Helper\CarrierGroup $carrierGroupHelper) {
$this->carrierGroupHelper = $carrierGroupHelper;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$transport = $observer->getEvent()->getTransport();
$order = $transport->getOrder();
$orderDetail = $this->carrierGroupHelper->getOrderCarrierGroupInfo($order->getId());
if($order != null)
{
foreach ($orderDetail as $orderData) {
$ddate = array_key_exists('delivery_date', $orderData) ? $orderData['delivery_date'] : '';
$transport['cddeliveryDate'] = date( 'F d, Y', strtotime( $ddate ) );
}
}
}
}```
sales_email/general/async_sending
? Are emails being sent on submit or being triggered later on?