无法在Magento 2中删除块product.info.options.configurable

问题描述 投票:1回答:1

无法删除指定的特定块:

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 subversion,composer,IDE,PHP和其他东西版本也无关紧要,因为remove命令适用于上面的块。但是,当我尝试时:

<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个回答
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文件中使用另一个引用名称。

© www.soinside.com 2019 - 2024. All rights reserved.