0

I have created module to get order_id to get some custom information from database.

events.xml

<?xml version="1.0"?>
<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_custom_variable_to_Order"
              instance="Customedit\GetOrder\Observer\ObserverforAddCustomVariable"/>
</event>

ObserverforAddCustomVariable.php

namespace Customedit\GetOrder\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Framework\App\ObjectManager;
class ObserverforAddCustomVariable implements ObserverInterface
{

  public function __construct()
  {
  }
  public function execute(\Magento\Framework\Event\Observer $observer)
  {
    $transport = $observer->getTransport();
    $order = $transport->getOrder()->getId();
    $transport['Get_OrderId'] = $order;
  }
}

Now, I want to check that I can get orderId with

{{var Get_OrderId}}

it returned nothing.

Did I use wrong method or did something wrong?

If I can't get order_id. Can I get increment_id instead?

1 Answer 1

0

You are using correct event for process email templates for new order

See some notes and example in https://magento.stackexchange.com/a/358613/91782

If you want to operate order data better to extend and use order_data array.

The Order ID is already present in template and you can use following to render it in template

{{var order_id}}
1

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.