1

I want to set the template variable in Magento RMA email template using observer or plugin. Unlike in email order (i.e. email_order_set_template_vars_before) or email shipment (i.e. email_shipment_set_template_vars_before), default Magento's RMA doesn't have custom event for passing template variable. So, anyone has idea regarding that.

Thanks in advance !!!

1 Answer 1

0

To add a custom template variable in the email template for Magento RMA in Magento 2 Enterprise, you can use a plugin to modify the Magento\Rma\Model\Rma class.

Here are the steps to add a template variable in the email template for Magento RMA:

  1. Create a module and define the plugin in the module's di.xml file:

    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
      <type name="Magento\Rma\Model\Rma">
          <plugin name="add_custom_template_variable" type="Vendor\Module\Plugin\RmaPlugin" />
      </type>
    </config>
    
  2. Create the plugin class RmaPlugin and add the template variable in the beforeSendEmail method:

     <?php
     namespace Vendor\Module\Plugin;
    
     use Magento\Rma\Model\Rma;
    
     class RmaPlugin
     {
         public function beforeSendEmail(Rma $subject, $templateVars, $area, $store)
         {
             $templateVars['custom_variable'] = 'Custom Value';
             return [$templateVars, $area, $store];
         }
     }
    

In this example, the template variable $custom_variable is added with the value Custom Value.

  1. Use the template variable in the email template for Magento RMA by adding the variable inside the curly braces:

    {{custom_variable}}
    

That's it! Now you can use the custom template variable in the email template for Magento RMA.

9
  • Hello Navneet, In the RMA module, there is no file like this Magento\Rma\Block\Adminhtml\Rma\View Mar 16, 2023 at 11:00
  • Are you using Magento EE or CE? If you are using CE, then you must have installed a third-party module, because Magento EE has a built-in module. Mar 16, 2023 at 11:55
  • I am using Magento EE only Mar 16, 2023 at 12:01
  • I have updated my answer can you try with that Mar 16, 2023 at 13:00
  • I have checked the core magento rma module and I don't find the function sendEmail in given plugin !!! Mar 16, 2023 at 14:14

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.