简体   繁体   English

扩展确认电子邮件 Magento 2

[英]Extending confirmation emails Magento 2

I would like to add conditional text into my confirmation emails in magento 2. As in:我想在 magento 2 中将条件文本添加到我的确认电子邮件中。如:

 {{if order contains item }}

 text

 {{else order doesnt contain item}}

 other text

At the moment I am aware that the email displays items with this:目前我知道电子邮件显示的项目如下:

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

Is this configurable?这个可以配置吗?

Thanks谢谢

For this purpose, i use an external phtml template :为此,我使用外部 phtml 模板:

  • in the design area, create the module you want to modify, I your case, it's Magento_Sales在设计区,创建你要修改的模块,我你的情况,是Magento_Sales

  • in templates directory add /email/your-template.phtml :在模板目录中添加 /email/your-template.phtml :

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

In your-template.phtml, use php as usuale在 your-template.phtml 中,照常使用 php

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

In the HTML template the-email-to-modify.html, you can include your template and send any variables you want, here the customer name :在 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'}}

et voila ^^等等 ^^

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM