Question

I'm using Magento 2.1 I've created my own theme called 'MP/basic', which is based on Luma. I created the theme.xml, registration.php, the web folder with everything I need inside it. I can choose that new theme in Admin panel and it appears correctly with my logo on the frontend.

I'm trying to remove the catalog.compare.link block in top.links and other stuff.

The layout for this block seems to be defined in

/vendor/magento/module-catalog/view/frontend/layout/default.xml

I tried to add

<referenceBlock name="catalog.compare.link" remove="true" />

And it works as expected, but I'm not supposed to change vendor files. So I'm looking for the correct folder in which to create my own default.xml file to place the new code: For now I have default.xml, and I modified catalog_product_view.xml in wich I wrote :

<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>      
<referenceBlock name="product.info.sku" remove="true" /> 
<referenceBlock name="view.addto.compare" remove="true" />  
<referenceBlock name="product.info.mailto" remove="true" />
</body>
</page>

I've looked everywhere in the documentation and online but cannot find the correct information on this subject. I've read all other question on magento.stackexchange without success.

. I've tried several locations, including the one where my theme is defined :

/app/design/frontend/MP/basics/Magento_Catalog/layout/default.xml
OR 
/app/design/frontend/MP/basics/Magento_Catalog/page_layout/override/default.xml
OR 
/app/design/frontend/MP/basics/Magento_Catalog/layout/override/default.xml
OR 
/app/design/frontend/MP/basics/Magento_Catalog/layout/override/base/default.xml

and several other locations.

After each attempt, I cleaned/flushed the cache,deleted pub/static/, and var/view_processed/ redeployed static content, and did a php bin/magento setup:upgrade, without luck. The new default.xml or catalog_product_view.xml is not displayed, as it is when I modify directly luma's files.

I'm in developper mode, but it's not working in production. I'm using redis for the cache and I see in the console everything is flushed correctly.

Please can someone tell me what i'm doing wrong, or the good way to go (it is driving me crazy)

Thanks a lot, WM

Was it helpful?

Solution 3

As I found a solution, I answer to my question.

First of all, I tried every path I found in the online documentation. Finding a good and clear information is pretty hard. Sometimes the documentation is outdated and refer to path that changed, or are just valid for the git version of magento 2.

I tried to extend or override the catalog_product_view.xml defined in the luma theme in order to remove block refering to the "compare" feature. The solutions posted by Rakesh and SH Patel didn't work, So I decided to try to copy/paste the catalogue_product_view.xml from the luma theme in my theme folder, and set the blank theme as parent in the theme.xml and add the folowing lines :

    <referenceBlock name="product.info.sku" remove="true" />
    <referenceBlock name="view.addto.compare" remove="true" />
    <referenceBlock name="product.info.mailto" remove="true" />

But It didn't work... Something is missing, in the xml file or maybe elsewhere (I think an error message is missing somewhere in the magento code).

Now the solution : In order to extend or override the luma theme, you need to copy past the content of vendor/magento/theme-frontend-luma/ in your own theme folder (app/design/frontend/vendor/theme). Modify the registration.php and set your theme path (vendor/theme), and theme.xml with your theme name.

This solution is more stable because you only depend on the blank theme. So if the magento team decide to uptade the luma theme, you won't be affected.

Then, if you want to remove the compare link in the product page, just edit your app/design/frontdend/vendor/theme/Magento_Catalog/layout/catalog_product_view.xml

    <referenceBlock name="view.addto.compare" remove="true" />

If you need to remove the sku code, or the mailto link youcan also add :

    <referenceBlock name="product.info.sku" remove="true" />
    <referenceBlock name="product.info.mailto" remove="true" />

Do not remove var/* folder or pub/static/* Do not re-deploy static content, you'll just waste your time (even in production mode). Just disable cache, make your modification and refresh the page, it's working. No need to delete/regenerate everything ...

OTHER TIPS

You have to just keep below code inside default.xml file to remove compare functionality from your site,

path : app/design/frontend/MP/basics/Magento_Catalog/layout/default.xml

 <?xml version="1.0"?>

    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">   
        <body>

            <referenceBlock name="category.product.addto.compare" remove="true"/>
            <referenceBlock name="catalogsearch.product.addto.compare" remove="true"/>
            <referenceBlock name="view.addto.compare" remove="true"/>
            <referenceBlock name="related.product.addto.compare" remove="true"/>
            <referenceBlock name="upsell.product.addto.compare" remove="true"/>
            <referenceBlock name="crosssell.product.addto.compare" remove="true"/>
            <referenceBlock name="view.addto.compare.bundle" remove="true"/>
            <referenceBlock name="catalog.compare.link" remove="true" />

        </body>
    </page>

Remove var folder and clear cache.

Add below code to given file path, you should crete default.xml in below path

/app/design/frontend/MP/basic/Magento_Theme/layout/default.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2016 Magento. 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>
        <referenceBlock name="catalog.compare.link" remove="true" />
    </body>
</page>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top