1

Cannot remove specific block named:

product.info.options.configurable

In Magento 2. This is the layout file I'm trying to change:

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

The content of it is:

<!--
/**
 * 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>

As you can see the last part is:

        <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>

I am sure that my code is correct as:

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

Can successfully remove the wrapper block and I can see it removed. This shows me that: Magento is correct. My layout file is read by Magento. Cache clear works. generated code clearing works. The way I'm writing that single line also works as it really removes the wrapper block. My operating system version, Magento subversion, composer, IDE, PHP and other things versions are also irrelevant as the remove command works for the above block. But then, when I try:

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

It just doesn't work. I then put all possible combinations of lines to remove this which I found on every single forum I could search and it still doesn't remove the block I want:

        <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>

As you can see, I used all possible options. The block name, It's alias, remove="true", display="false", inside wrapper block, inside wrapper block as a container, each of above lines alone, a combination of above lines, and so on and so on. Any ideas are highly appreciated. Thanks in advance.

Roman Melnyk
  • 1,097
  • 1
  • 8
  • 21
Aario
  • 31
  • 5

1 Answers1

2

So!

What was the problem?

When enabling template path hints in Magento backend, one can then search for the template name in magento xml files to figure out which block renders that template which was what I did. But trying to remove that block didn't help as I described above. Even when I removed the block from the original magento xml file. So I realized the template is rendered from somewhere else and the xml file I'm trying to override is actually an orphaned obsolete piece of code which is commonplace is Magento!

Solution

The template was called also in a php file:

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

Which was extending the original block. This new child block is then called in another layout xml file:

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

Which has a different reference name:

product.info.options.swatches

Tried removing that instead:

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

And it worked!

Summary

The layout.xml file I was trying to remove part of it was partially obsolete and the template file was used in another block with another reference name in another xml file.

Aario
  • 31
  • 5