I have observer for email_order_set_template_vars_before where i am setting some email template variable to use in order confirmation email.

Now i want to find which products customer has ordered in that order and depending on that set value for email template variable.

So how can i access order object inside this observer method?


I found answer myself. Sharing here so it may help someone.

We can get Order object inside execute method of observer as below:

public function execute(\Magento\Framework\Event\Observer $observer)

        $transport = $observer->getTransport();
        $orderId=$order->getEntityId(); /** We can call any method of $order as usual **/


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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