扩展确认电子邮件Magento 2


Extending confirmation emails Magento 2

我想在magento 2的确认邮件中添加条件文本。如:

 {{if order contains item }}
 text
 {{else order doesnt contain item}}
 other text

现在我知道电子邮件显示的项目是这样的:

{{layout handle="sales_email_order_items" order=$order area="frontend"}}

是可配置的吗?

谢谢

为此,我使用了一个外部php模板:

  • 在设计区,创建你想要修改的模块,在你的例子中,它是Magento_Sales

  • 在模板目录add/email/your-template。php:

Magento_Sales
    /email
       the-email-to-modify.html
    /templates
        /email
            your-template.phtml

模板。

<?php
//your code, with the test
// to get the variables use:
$myvar=$this->getData('myvar');
...?>
<p>Hello <?php echo $myvar; ?></p>

在HTML模板the-email-to-modify. HTML中,您可以包含您的模板并发送任何您想要的变量,这里是客户名称:

<h1>The title</h1>
{{block class='Magento''Framework''View''Element''Template' 
    myvar=$customer.name area='frontend' 
    template='Magento_Sales::email/your-template.phtml'}}