【问题标题】:Magento2 - Override Template order summary in sales email orderMagento2 - 在销售电子邮件订单中覆盖模板订单摘要
【发布时间】:2018-09-19 15:19:15
【问题描述】:

我有使用以下内容呈现订单摘要的模板

{{layout handle="sales_email_order_items" order=$order area="前端"}}

它从以下模板中获取代码

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

所以我想用我的自定义模块文件覆盖这个文件并使用这个。

我创建了一个模块“Corra_Sales

我把.phtml放在这里

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

另外,我用文件创建了布局:

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

另外,我尝试过:

<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>

我清除缓存、删除 var 文件夹、重建等。

但它仍然无法正常工作,有人可以告诉我我做错了什么总是拿这个文件->?

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

【问题讨论】:

  • 正如官方文档(devdocs.magento.com/guides/v2.2/frontend-dev-guide/templates/…)所说——“主题模板覆盖模块模板”
  • 如果你能解释一下你为什么要这样做,也许我们能想出办法
  • @AleksandrasGavinčiuk 我需要在模板中显示自定义功能,但我无法修改设计中的模板,这就是我创建新模块的原因。
  • 为什么不能修改主题文件夹中的那个?你真的需要覆盖它,或者你可以在另一个模板中添加你的功能?
  • 为什么不能修改主题文件夹中的那个?因为这是客户端的要求:S 您实际上需要覆盖它,或者您可以在另一个模板中添加您的功能?我需要覆盖上述文件。

标签: php magento magento2 magento2.1


【解决方案1】:

这在 2.2.5 下对我有用,您的模块文件需要说明遵循 Vendor/ModuleExample/etc/module.xml 的顺序

<?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Vendor_ModuleExample" setup_version="1.1.0">
        <sequence>
            <module name="Magento_Sales"/>
        </sequence>
    </module>
</config>

您还需要考虑到该块没有名称,因此您可能需要使用别名。

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

如果有帮助,请告诉我。

来源: https://magento.stackexchange.com/questions/177343/override-magento-2-email-items-order-default-phtml https://www.classyllama.com/blog/template-override-m2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多