Magento 2: Как отобразить имя продукта и цену продукта в пользовательском шаблоне электронной почты?
Это мой файл наблюдателя, из которого я передаю значения в email_template.html
foreach($items as $item) {
$productIds[]= $item->getProductId();
$productName[]= $item->getSku();
$productPrice[] = $item->getPrice();
// $productQuantity[]= $item->getQty();
}
$transport = $this->_transportBuilder->setTemplateIdentifier('order_template')
->setTemplateOptions($templateOptions)
->setTemplateVars($templateVars)
->setFrom($from)
->addTo($to)
->getTransport();
$transport->sendMessage();
$this->inlineTranslation->resume();
Как я могу получить значения $productName
и $productPrice
в моем шаблоне электронной почты.
Я пытался, но не получилось
email_template.html
<table class="email-items">
<thead>
<tr>
<th class="item-info">{{trans "Items"}}</th>
<th class="item-info">{{trans "Qty"}}</th>
<th class="item-info">{{trans "Sku"}}</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{var $productName.getSku()}}</td>
<td>{{var myvar8|raw}}</td>
<td>{{var $productPrice.getPrice()}}</td>
</tr>
</tbody>
</table>
2
Author: Khoa TruongDinh, 2016-09-16
1 answers
В html-шаблоне электронной почты мы можем добавить макет и передать объект заказа в этот макет. Например, в вашем макете:
email_template.html
{{layout handle="sales_custom_email_order_items" order=$order area="frontend"}}
Создайте свой собственный макет:
view/frontend/layout/sales_custom_email_order_items.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Email Order Items List" design_abstraction="custom">
<body>
<block class="Vendor\Module\Block\Order\Email\Items" name="items" template="email/items.phtml" cacheable="false">
<!--Add more stuff here-->
</block>
</body>
</page>
А затем создайте Vendor\Module\Block\Order\Email\Items
и email/items.phtml
.
Мы должны взглянуть на некоторые файлы по умолчанию:
--vendor/magento/module-sales/view/frontend/email/order_new.html
--vendor/magento/module-sales/view/frontend/layout/sales_email_order_items.xml
--vendor/magento/module-sales/view/frontend/layout/sales_email_order_renderers.xml
--vendor/magento/module-sales/Block/Order/Email/Items/Order/DefaultOrder.php
--vendor/magento/module-sales/Block/Order/Email/Items.php
1
Author: Khoa TruongDinh, 2016-09-20 15:18:49