cancel
Showing results for 
Search instead for 
Did you mean: 

Magento2 override sales email templates

Magento2 override sales email templates

Hi to all, I'm going crazy. I've read a lot of tutorial and marked "as solved" topics on override template on sales email.

I'm trying to customize the sales_email_order_items, so I've create a file in [ModuleDir]/view/frontend/layout/sales_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">
    <body>
        <referenceBlock name="items">
            <block class="Magento\Sales\Block\Order\Email\Items"  template="Vendor_Module::email/items.phtml"/>
        </referenceBlock>
    </body>
</page>

and created my custom template in [ModuleDir]/view/frontend/templates/email/items.phtml

cleared cache and compiled, but nothing changed.

 

Someone can help me?

Tags (2)
4 REPLIES

Re: Magento2 override sales email templates

hi @dandreoli

 

 if you want to override the template use below code.

 

 

 

<referenceBlock name="items">
            <action method="setTemplate" >
                <argument name="template" xsi:type="string">Vendor_Module::email/items.phtml</argument>
            </action>
</referenceBlock>
Find helpful ? Consider Giving Kudos to this post.
Problem solved? Click Accept as Solution!"
Qaisar Satti

Re: Magento2 override sales email templates

This solution with <action> is deprecated, anyway I've just tried and It doesn't work

Re: Magento2 override sales email templates

thanks for pointing that out for me. but it is working for me. Try this
<referenceBlock name="items">
            <arguments>
                <argument name="template" xsi:type="string">Vendor_Module::email/items.phtml</argument>
            </arguments>
        </referenceBlock>


Reference
Find helpful ? Consider Giving Kudos to this post.
Problem solved? Click Accept as Solution!"
Qaisar Satti

Re: Magento2 override sales email templates

I've already tried this solution. At the end I0ve found an alternative way to solve.

 

I've delcare in di.xml 

<preference for="Magento\Sales\Block\Order\Email\Items" type="Vendor\Module\Block\Order\Email\Items" />

and create a class 

Vendor\Module\Block\Order\Email\Items

 

<?php

namespace Vendor\Module\Block\Order\Email;

class Items extends \Magento\Sales\Block\Order\Email\Items
{
}

and finally It uses my  template file