Magento 2如何在订购电子邮件中更改“要收取的总计”文本

时间:2019-01-28 13:31:48

标签: magento2

在Magento 2中,如何更改电子邮件中的“待收费总额”文本?

在此文件中找到文本vendor / magento / module-sales / Block / Order / Totals.php

如何将此文件覆盖到我的主题或模块?

谢谢 桑托什

1 个答案:

答案 0 :(得分:0)

要覆盖此类,您需要创建自己的类并扩展原始类。

您需要在di.xml文件中声明重写类。请按照以下步骤操作:

  

app / code / MilanDev / ExtendsCore / 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="MilanDev_ExtendsCore" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Sales"/>
        </sequence>
    </module>
</config>
  

app / code / MilanDev / ExtendsCore / 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\Totals" type="MilanDev\ExtendsCore\Rewrite\Magento\Sales\Block\Order\Totals"/>
</config>
  

app / code / MilanDev / ExtendsCore / Rewrite / Magento / Sales / Block / Order / Totals.php

<?php
namespace MilanDev\ExtendsCore\Rewrite\Magento\Sales\Block\Order;

class Totals extends \Magento\Sales\Block\Order\Totals
{

    /**
     * Initialize order totals array
     *
     * @return $this
     */
    protected function _initTotals()
    {
        // ...........

        if ($this->getOrder()->isCurrencyDifferent()) {
            $this->_totals['base_grandtotal'] = new \Magento\Framework\DataObject(
                [
                    'code' => 'base_grandtotal',
                    'value' => $this->getOrder()->formatBasePrice($source->getBaseGrandTotal()),
                    'label' => __('Your custom text'), // changed
                    'is_formated' => true,
                ]
            );
        }

        // ........
    }
}