I have added an observer using the code below, it triggers correctly but the translated text is English. It is supposed to be Danish. When I call the same code from other places it uses the correct locale.
What am I missing? Do I need to set the locale explicitly when using observers?
events.xml
<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="add_DeliveryTime_variable_to_Order"
instance="ZitecCheckoutObserverDeliveryTime" />
</event>
</config>
DeliveryTime.php
class DeliveryTime implements ObserverInterface
{
/**
* @var C5OrderService
*/
private $c5OrderService;
public function __construct(C5OrderService $c5OrderService) {
$this->c5OrderService = $c5OrderService;
}
/**
*
* @param Observer $observer
* @return void
*/
public function execute(Observer $observer)
{
$transport = $observer->getEvent()->getTransport();
/** @var Order $order */
$order = $transport->getOrder();
$transport['DeliveryTime'] = $this->c5OrderService->getMaximumDeliveryTimeText($order);
}
}
C5OrderService.php
class C5OrderService {
public function getMaximumDeliveryTimeText($order){
return __('10 working days');
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…