【问题标题】:Cannot remove block product.info.options.configurable in Magento 2无法在 Magento 2 中删除块 product.info.options.configurable
【发布时间】:2019-09-03 02:24:55
【问题描述】:

无法删除特定的块命名:

product.info.options.configurable

在 Magento 2 中。 这是我要更改的布局文件:

vendor/magento/module-configurable-product/view/frontend/layout/catalog_product_view_type_configurable.xml

它的内容是:

<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <attribute name="class" value="page-product-configurable"/>
        <referenceBlock name="head.components">
            <block class="Magento\Framework\View\Element\Js\Components" name="configurableproduct_product_view_head_components" template="Magento_ConfigurableProduct::js/components.phtml"/>
        </referenceBlock>
        <referenceContainer name="product.info.type">
            <block class="Magento\ConfigurableProduct\Block\Product\View\Type\Configurable" name="product.info.configurable" as="product_type_data" template="Magento_Catalog::product/view/type/default.phtml"/>
            <container name="product.info.configurable.extra" after="product.info.configurable" as="product_type_data_extra" label="Product Extra Info">
                <block class="Magento\ConfigurableProduct\Block\Stockqty\Type\Configurable" name="product.info.configurable.extra.catalog_inventory_stockqty_composite" template="Magento_CatalogInventory::stockqty/composite.phtml"/>
            </container>
        </referenceContainer>
        <referenceBlock name="product.info.options.wrapper">
            <block class="Magento\ConfigurableProduct\Block\Product\View\Type\Configurable" name="product.info.options.configurable" as="options_configurable" before="-" template="Magento_ConfigurableProduct::product/view/type/options/configurable.phtml"/>
        </referenceBlock>
    </body>
</page>

如你所见,最后一部分是:

        <referenceBlock name="product.info.options.wrapper">
            <block class="Magento\ConfigurableProduct\Block\Product\View\Type\Configurable" name="product.info.options.configurable" as="options_configurable" before="-" template="Magento_ConfigurableProduct::product/view/type/options/configurable.phtml"/>
        </referenceBlock>

我确信我的代码是正确的:

<referenceBlock name="product.info.options.wrapper" remove="true"/>

可以成功删除包装块,我可以看到它已删除。这向我表明: Magento 是正确的。 我的布局文件由 Magento 读取。 缓存清除工作。 生成的代码清除工作。 我写那一行的方式也有效,因为它确实删除了包装块。 我的操作系统版本、Magento 颠覆、作曲家、IDE、PHP 和其他东西版本也无关紧要,因为删除命令适用于上述块。 但是,当我尝试时:

<referenceBlock name="product.info.options.configurable" remove="true"/>

它只是不起作用。 然后,我将所有可能的行组合删除了我在可以搜索的每个论坛上找到的它,但它仍然没有删除我想要的块:

        <referenceBlock name="options_configurable" remove="true"/>
        <referenceBlock name="product.info.options.configurable" remove="true"/>
        <referenceBlock name="options_configurable" display="false"/>
        <referenceBlock name="product.info.options.configurable" display="false"/>
        <referenceContainer name="product.info.options.wrapper">
            <referenceBlock name="options_configurable" remove="true"/>
            <referenceBlock name="product.info.options.configurable" remove="true"/>
            <referenceBlock name="options_configurable" display="false"/>
            <referenceBlock name="product.info.options.configurable" display="false"/>
        </referenceContainer>
        <referenceBlock name="product.info.options.wrapper">
            <referenceBlock name="options_configurable" remove="true"/>
            <referenceBlock name="product.info.options.configurable" remove="true"/>
            <referenceBlock name="options_configurable" display="false"/>
            <referenceBlock name="product.info.options.configurable" display="false"/>
        </referenceBlock>
        <referenceContainer name="content">
            <referenceBlock name="options_configurable" remove="true"/>
            <referenceBlock name="product.info.options.configurable" remove="true"/>
            <referenceBlock name="options_configurable" display="false"/>
            <referenceBlock name="product.info.options.configurable" display="false"/>
        </referenceContainer>

如您所见,我使用了所有可能的选项。块名,别名,remove="true"display="false",内部包装块,内部包装块作为容器,上面的每一行单独,上面的行的组合,等等。 任何想法都受到高度赞赏。提前致谢。

【问题讨论】:

    标签: xml magento2 block


    【解决方案1】:

    所以!

    出了什么问题?

    在 Magento 后端启用模板路径提示时,可以在 magento xml 文件中搜索模板名称,以确定哪个块呈现了我所做的模板。但是正如我上面描述的那样,试图删除该块并没有帮助。即使 我从原始 magento xml 文件中删除了该块。所以我意识到模板是从其他地方呈现的,而我试图覆盖的 xml 文件实际上是一段孤立的过时代码,这是很常见的 Magento!

    解决方案

    模板也在一个 php 文件中被调用:

    vendor/magento/module-swatches/Block/Product/Renderer/Configurable.php

    这是扩展原始块。然后在另一个布局 xml 文件中调用这个新的子块:

    vendor/magento/module-swatches/view/frontend/layout/catalog_product_view_type_configurable.xml

    有不同的参考名称:

    product.info.options.swatches
    

    尝试删除它:

    <referenceBlock name="product.info.options.swatches" remove="true"/>
    

    它成功了!

    总结

    我试图删除其中一部分的 layout.xml 文件已部分过时,并且模板文件在另一个块中使用,并且在另一个 xml 文件中具有另一个引用名称。

    【讨论】:

      猜你喜欢
      • 2021-03-16
      • 2015-03-27
      • 2021-10-07
      • 1970-01-01
      • 2016-12-04
      • 1970-01-01
      • 2022-11-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多