【问题标题】:How to override di.xml of core module in custom module Magento 2如何在自定义模块 Magento 2 中覆盖核心模块的 di.xml
【发布时间】:2020-07-16 16:39:05
【问题描述】:

我想从供应商模块的 di.xml 中删除一些部分。下面是要删除的部分示例。

<type name="Magento\Braintree\Block\GooglePay\Shortcut\Button">
        <arguments>
            <argument name="data" xsi:type="array">
                <item name="template" xsi:type="string">Magento_Braintree::googlepay/shortcut.phtml</item>
                <item name="alias" xsi:type="string">braintree.googlepay.mini-cart</item>
                <item name="button_id" xsi:type="string">braintree-googlepay-mini-cart</item>
            </argument>
            <argument name="payment" xsi:type="object">BraintreeGooglePay</argument>
        </arguments>
    </type>

如何在自定义模块中使用覆盖 di.xml 来删除它。

【问题讨论】:

  • 为什么不完全删除按钮?或者你想改变论点?

标签: magento2 php-7.3


【解决方案1】:

你试过放吗

<type name="Magento\Braintree\Block\GooglePay\Shortcut\Button">
    <arguments>
    </arguments>
</type>

内部自定义di.xml? 然后运行php bin/magento setup:upgrade,使依赖关系更新。

要完全删除按钮,请搜索出现的块类并在自定义模块(Vendor/Module/view/frontend/layout/{{THE_LAYOUT_NAME}}.xml)中创建自己的布局文件(-s),内容如下:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="{{GOOGLE_PAY_BUTTON_BLOCK_NAME}}" remove="true"/>
    </body>
</page>

编辑:按钮块名称在布局文件中由&lt;block&gt; 标记的name 属性定义。

【讨论】:

    【解决方案2】:

    感谢您分享可能的选项。

    对我有用的解决方案是将参数标签内的项目设为空。 在我的场景中,我不希望在依赖注入中使用这个项目。这对我有用。

    在自定义模块 etc/frontend/di.xml 中添加以下代码

    <type name="Magento\Braintree\Block\GooglePay\Shortcut\Button">
         <arguments>
            <argument name="data" xsi:type="array">
               <item name="template" xsi:type="null" />
               <item name="alias" xsi:type="null" />
               <item name="button_id" xsi:type="null" />
            </argument>
            <argument name="payment" xsi:type="object">BraintreeGooglePay</argument>
         </arguments>
    </type>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-16
      • 1970-01-01
      • 1970-01-01
      • 2020-05-22
      相关资源
      最近更新 更多