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.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI 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.
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:
If you have these basics now, all you have to do is:
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.
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.
No matter which email template you want to change on non-working days. If you want to change the default magento templates, then you have to override few core files using plugin as this is the standard way. Create your own module first, in which define your custom email templates in email_templates.xml. The files you will override will contain
$this->getTemplateId()
Define you template id as:-
const XML_PATH_EMAIL_TEMPLATE_FIELD = 'section/group/your_email_template_field_id';
const XML_PATH_EMAIL_TEMPLATE_FIELD2 = 'section/group/your_email_template_field_id_2';
Then just put $this->getTemplateId()
inside if else as:-
if($day==$working_day) {
$this->temp_id = $this->getTemplateId(self::XML_PATH_EMAIL_TEMPLATE_FIELD);
}
else {
$this->temp_id = $this->getTemplateId(self::XML_PATH_EMAIL_TEMPLATE_FIELD2);
}
$this->inlineTranslation->suspend();
$this->generateTemplate($emailTemplateVariables,$senderInfo,$receiverInfo);
$transport = $this->_transportBuilder->getTransport();
$transport->sendMessage();
$this->inlineTranslation->resume();
Above code may not be suitable for your condition. But as per your query to change email templates on non-working days. You can follow the same logic. Or you can send me your code for more specific answer. Hope it helps!!