如何覆盖自定义模块Magento 2中核心模块的di.xml

How to override di.xml of core module in custom module Magento 2

我想从供应商模块的 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 来删除它。

你试过

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

内部习俗di.xml? 然后运行php bin/magento setup:upgrade,这样依赖就更新了

要完全删除按钮,请搜索出现的块 class 并在自定义模块 (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>

编辑:按钮块名称在布局文件中由 <block> 标签的 name 属性定义。

感谢分享可能的选项。

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

自定义模块中添加了以下代码 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>