扩展确认电子邮件Magento 2

时间:2016-10-04 11:10:57

标签: php email magento2

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

 {{if order contains item }}

 text

 {{else order doesnt contain item}}

 other text

目前我知道该电子邮件显示的内容为:

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

这是可配置的吗?

由于

1 个答案:

答案 0 :(得分:1)

为此,我使用外部phtml模板:

  • 在设计区域中,创建您要修改的模块,我的情况下,它是Magento_Sales

  • 模板目录中的
  • 添加/email/your-template.phtml:

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

在your-template.phtml中,使用php as usuale

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

在HTML模板-mail-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'}}

et voila ^^