Magento2 – Use Different Email Template for Order Confirmation on Non-Working Days

email-templatesmagento2

I wonder if there is a build in magento module which manages emails for non working days. The email sent on non working day will be different than the email sent on working day.

If no module exist, please guide me to the recommended way to do it.

Best Answer

There is no such a thing as you want to and therefore customization is required, however it is quite easy to achieve. I assume that you have basic knowledge on how to create your own standalone module and how to write plugins or override classes. If not then please read resources as the first step:

  1. Hello World Module
  2. DI

If you have these basics now, all you have to do is:

  1. Create a new module basics (registration.php, module.xml, composer.json)
  2. Override Magento\Sales\Order\Email\SenderBuilder.php

There you have a send method but more importantly, there is a protected configureEmailTemplate method [96] which holds configuration logic for the email. all you have to do is add new logic with regards to your data requiremnts and pass your template_id in:

$this->transportBuilder->setTemplateIdentifier($this->templateContainer->getTemplateId());

Preferably you will create a new class responsible for resolving template_id with regards to requirements, inject it into a Sender's constructor and delegate revolving template.

  1. To add your own order email template you must create etc/email_templates.xml inside of your module and add new template, eg:

    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd"> <template id="sales_email_order_template" label="New Order" file="order_new.html" type="html" module="Magento_Sales" area="frontend"/> </config>

Element's attributes are obvious and you can always read any file in any module to get more examples.

Related Topic