1

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

3 Answers 3

0

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.

2
  • This path is not working for me as said in my question, did you mean using a different default.xml ? Did you find an error in mine ? Thanks for your comment .
    – will.I4M
    Oct 8, 2016 at 10:38
  • About the default.xml : I tried to put a default.xml with this content in app/design/frontend/MP/basics/Magento_Catalog/layout/default.xml, but no luck ! No changes. How is this possible that my theme is correctly installed/detected (my logo is curretly displayed in the front) and that it is impossible to override the default.xml and catalog_product_view.xml ? I also tried to put thoses files in <theme_dir> |__/<Namespace_Module> |__/layout |__/override |__/theme |__/<Parent_Vendor> |__/<parent_theme> But, it doesn't work
    – will.I4M
    Oct 9, 2016 at 20:28
0

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>
1
  • I tried this math, but it's not working for the catalog_product_view.xml, For the default.xml, it's different from mine, did you find an error in my file ? Could you tell me more ? Thanks for your comment
    – will.I4M
    Oct 8, 2016 at 10:41
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.