3

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?

2 Answers 2

4

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();
        $order=$transport['order'];
        $orderId=$order->getEntityId(); /** We can call any method of $order as usual **/

    }

1
  • How to get shipping information? Commented Dec 21, 2022 at 5:57
0

You can use following code to get order data

public function execute(\Magento\Framework\Event\Observer $observer)
{
    $transport = $observer->getTransport();
    $order = $transport->getData('order');
    $orderId = $order->getId();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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