1

I have the template that is using the following to render order summary

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

it is taking the code from the following template

/app/design/frontend/Corra/Mytheme/Magento_Sales/templates/email/items/order/default.phtml

So I want to override this file with my custom module file and use this one.

I created a module "Corra_Sales"

I put the .phtml here

/app/code/Corra/Sales/view/frontend/templates/email/items/order/default.phtml

Also, I created the layout with the file:

/app/code/Corra/Sales/view/frontend/layout/sales_email_order_renderers.xml

The code inside file is:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Email Creditmemo Items List" design_abstraction="custom">
    <body>
        <referenceBlock name="sales.email.order.renderers">
            <block class="Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder" as="default" template="Corra_Sales::email/items/order/default.phtml"/>
        </referenceBlock>
    </body>
</page>

Also, I tried with :

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Email Creditmemo Items List" design_abstraction="custom">
    <body>
        <referenceBlock name="sales.email.order.renderers">
            <arguments>
                <argument name="template" xsi:type="string">Corra_Sales::email/items/order/default.phtml</argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

I clear cache, remove var folder, rebuild, etc.

But it still not working, someone could tell me what I am doing wrong that always take this file ->?

/app/design/frontend/Corra/Mytheme/Magento_Sales/templates/email/items/order/default.phtml

2 Answers 2

2

the block referenced by sales.email.order.renderers.default is the one to override the template

both layout definitions below should do the work and the first layout definition is now deprecated:

<?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="sales.email.order.renderers.default">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Mbs_EmailSaleOverride::sales_item.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

below is the new notation to take over the block template:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="sales.email.order.renderers.default">
            <arguments>
                <argument name="template" xsi:type="string">Mbs_EmailSaleOverride::sales_item.phtml</argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

Now, the emails in Magento are more complex than normal pages and I have today written a plugin that takes over the function getTemplate for the block \Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder and this is finally successfully overriding the template as expected:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder">
        <plugin name="takeovertemplate" type="Mbs\EmailSaleOverride\Plugin\OrderItemDefaultRenderer" />
    </type>
</config>

<?php
namespace Mbs\EmailSaleOverride\Plugin;

class OrderItemDefaultRenderer
{
    public function testafterGetTemplate()
    {
        return 'Mbs_EmailSaleOverride::sales_item.phtml';
    }
}
6
  • why you put the sales_item.phtml if I modified the default.phtml file ? Commented Sep 23, 2018 at 14:50
  • default.phtml would work too, it is just the way I named my template indeed Commented Sep 23, 2018 at 15:01
  • it does not work. still getting /app/design/frontend/Corra/Mytheme/Magento_Sales/templates/email/items/order/default.phtml file. Also, the file app/code/Corra/Sales/view/frontend/layout/sales_email_order_renderers.xml is Commented Sep 24, 2018 at 14:13
  • code<?xml version="1.0"?> <page xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Email Creditmemo Items List" design_abstraction="custom"> <body> <referenceBlock name="sales.email.order.renderers.default"> <action method="setTemplate"> <argument name="template" xsi:type="string">Corra_Sales::email/items/order/default.phtml</argument> </action> </referenceBlock> </body> </page> code Commented Sep 24, 2018 at 14:15
  • Also as the official documentation says devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/… action is deprecated Commented Oct 1, 2018 at 22:57
0
<?xml version="1.0"?>
<!--
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <referenceBlock name="sales.email.order.renderers.default" template="Moazzam_CustomSales::email/items/order/default.phtml"  />
</body>
</page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.