0

There is layout configuration file module-sales/view/frontend/layout/sales_email_order_renderers.xml:

<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="email/items/order/default.phtml"/> </referenceBlock> </body> </page>

I need to change default template for block Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder. I have created own configuration update .../view/frontend/layout/sales_email_order_renderers.xml in own module with:

<referenceBlock name="default"> <action method="setTemplate"> <argument name="template" xsi:type="string">Vendor_Module::email/items/order/default.phtml</argument> </action> </referenceBlock>

but default template is used for the block as before.

Can I change template for block Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder using layout updates?

2 Answers 2

2

Here is the code that i use for override default renderer of email template.

Vendor/Module/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder" type="Vendor\Module\Block\Order\Email\Items\Order\DefaultOrder" />
</config>

Vendor/Module/Block/Order/Email/Items/Order/DefaultOrder.php

class DefaultOrder extends \Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder
{
    public function setTemplate($template) {
        return parent::setTemplate('Vendor_Module::email/items/order/default.phtml');
    }
}

For override default.phtml file copy from magento\module-sales\view\frontend\templates\email\items\order\default.phtml to your module Vendor/Module/view/frontend/templates/email/items/order/default.phtml

1

You can just copy vendor/magento/module-sales/view/frontend/templates/email/items/order/default.phtml to app/design/frontend/[VENDOR]/[THEME]/Magento_Sales/templates/email/items/order/default.phtml and make your changes.

But you can also extend vendor/magento/module-sales/view/frontend/layout/sales_email_order_renderers.xml to app/design/frontend/[VENDOR]/[THEME]/Magento_Sales/layout/sales_email_order_renderers.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 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="email/items/order/default.phtml"/>
        </referenceBlock>
    </body>
</page>

And change whatever you need.

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.