无法删除命名为:
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",内部包装块,包装块作为容器,上面的每一行单独,上面行的组合等等。任何想法都会受到高度赞赏。提前谢谢。
发布于 2019-04-12 10:57:48
所以!
出了什么问题?
在Magento后端启用模板路径提示时,您可以在magento xml文件中搜索模板名称,以确定哪个块呈现模板,我就是这样做的。但是,正如我前面所描述的那样,试图删除这个块并没有帮助。即使在中,我也从原始的magento文件中删除了这个块。因此,我意识到模板是从其他地方呈现的,我试图覆盖的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中。
https://stackoverflow.com/questions/55649625
复制相似问题