Removing the Compare function in Magento, the easy way

I normally always want to remove the Compare/Add to Compare functionality from the Magento stores I create, and in the past have changed the template files as though the compare functionality is being hidden in the theme. In a lot of ways that’s probably a fairly reasonable way to disable it, but something seems clunky about going through a bunch of phtml files in Magento directories grep‘ing and replacing Add to Compare everywhere. I recently did it a different way, that although may be slightly less well separated from the core Magento functionality (in terms of keeping the changes at the UI layer) – I think it makes it clearer.

There are really only two three four (Thanks Matt and Paulo) steps to removing the compare functionality, and they’re all fairly easy, here’s how to do it:

Disable comparison functionality in Magento

I did this on the command line, but I’ll explain the commands for those of you stuck in cPanel/Plesk/GUI hell. These commands are all run from the root of your Magento store.

First create the local override directory:

mkdir -p app/code/local/Mage/Catalog/Helper/Product/

Making this local code directory that mirrors the core Mage folder structure will allow Magento to pick up your custom file. WHich we now make by copying the original from app/code/core/Mage/Catalog/Helper/Product/Compare.php and putting it in the new directory we made app/code/local/Mage/Catalog/Helper/Product/:

cp app/code/core/Mage/Catalog/Helper/Product/Compare.php app/code/local/Mage/Catalog/Helper/Product/

Now we just make one small change to the file, by basically telling this helper to never return a comparison URL, the front end will never show the add to compare links. The change is made in the getAddUrl() function.

 public function getAddUrl($product)
    {
        #return $this->_getUrl('catalog/product_compare/add', $this->_getUrlParams($product));
        # We disable compare functionality by commenting out the real return statement and returning false instead.
        # Returning a boolean from a function that should return a string, somewhere, a kitten dies.
        return false;
    }

Save the file and you’re done. Now when you refresh the product/category page (you disabled the Magento cache right?) then you’ll no longer see the ‘add to compare’ links by the add to cart buttons.

Remove the Compare sidebar element

There is also the matter of the sidebar element, here’s the easy way to get rid of that.

Edit your theme’s catalog.xml file which is found in the app/design/frontend/X/Y/layout/ directory, where X and Y are your theme and package, possibly just default and default.

Remove the part that looks like this within the first <default> element:

 <reference name="right">
            <block type="core/template" before="cart_sidebar" name="catalog.compare.sidebar" template="catalog/product/compare/sidebar.phtml"/>
            <block type="core/template" name="right.permanent.callout" template="callouts/right_col.phtml"/>
 </reference>

This has the nice side effect of removing the back to school specials block too, obviously if you are actually running a back to school special, then only remove this line from the <reference> element:

<block type="core/template" before="cart_sidebar" name="catalog.compare.sidebar" template="catalog/product/compare/sidebar.phtml"/>

Edit: Thanks to Matt for pointing this out.

To remove the compare sidebar from the My Account section of the Magento store edit the file: customer.xml inapp/design/frontend/X/Y/layout/. Find the section:

<customer_account>

And remove this line from it:

<block type="core/template" name="catalog.compare.sidebar" template="catalog/product/compare/sidebar.phtml"/>

Edit: And thanks to Paulo for pointing this out – the compare sidebar is also included in the reports.xml file, so remove it from there in the same way:

<default>
    <!-- Mage_Reports -->
    <reference name="right">
        <block type="reports/product_viewed" before="right.permanent.callout" name="right.reports.product.viewed" template="reports/product_viewed.phtml" />
        <block type="reports/product_compared" before="right.permanent.callout" name="right.reports.product.compared" template="reports/product_compared.phtml" />
    </reference>
</default>

The line to remove is:

<block type=”reports/product_compared” before=”right.permanent.callout” name=”right.reports.product.compared” template=”reports/product_compared.phtml” />

And that should be it, no more compare functionality. Maybe it’d be nice to make this into a Magento extension, so that it can be enabled and disabled on the admin interface. If there is enough interest in that, I’ll bundle up my code change, it’s really only one file, after all. If you’re after something like that – let me know.

You might also be interested in:

  1. Magento 1.4.0.1 Tax Calculation error – Out by a factor of 100
  2. How to set up Apache Virtual hosting on MAMP for Magento
  3. Magento Error: It is not safe to rely on the system’s timezone settings
  4. How to Bulk Enable Products when Google Checkout is Disabled in Magento
  5. Sitemap Submit – Magento Extension to Submit your Google Sitemap

42 Responses to “Removing the Compare function in Magento, the easy way”

  1. Nic July 13, 2009 at 10:04 pm #

    Ashley -

    Make it an extension! I think the majority of Magento deployments are manufacturers looking to sell only their product. It would be a welcome extension.

  2. Jerome July 23, 2009 at 9:44 pm #

    i will appreciate it as an extension !

    a well done and good find !

  3. Jerome July 23, 2009 at 11:31 pm #

    Damn, because of the command prompht, i screwed my whole website.

    Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 60:

    at treoo.com

  4. Ashley July 25, 2009 at 9:03 pm #

    Hi,

    That error tends to be caused by incorrect XML in your configuration files. Please check, and double check that you have not got an error in any of the XML files you edited. If still a problem please let me know. Unlikely to be caused by the commandline, in any case.

  5. Nic August 3, 2009 at 8:54 am #

    That simplexml error can also be because of browser cache/cookies

  6. Matt August 19, 2009 at 7:28 am #

    Thanks for this. I have followed your above instructions and Compare has been removed from everywhere except the My Account sidebar.. Where can I edit that out?

    An extension would be hugely appreciated, save people a lot of searching :-)

    Cheers!

  7. Ashley August 19, 2009 at 12:56 pm #

    Hi, Good point

    It’s in customer.xml, the section remove the line:

    Cheers,
    Ashley

  8. Ashley August 19, 2009 at 12:59 pm #

    doh, I’ll just update the article, the comments don’t take kindly to XML I see!

  9. Matt August 20, 2009 at 4:57 pm #

    Excellent, thanks Ashley :-)

  10. John Richardson October 6, 2009 at 10:01 am #

    Thank you!!! I must have looked for over two hours trying to find a solution… and none were so elegant and simple as yours. I really appreciate the help – finally I can get rid of the compare functionality :-) .

  11. Ian October 26, 2009 at 9:53 pm #

    Nice one! It’d be nicer as an extension ;)

  12. Alex December 29, 2009 at 12:04 pm #

    Please, pelase make a extension – for my sake and surely for many, many magento users. Not many need that compare thing.

  13. David March 24, 2010 at 5:14 pm #

    YES!! EXTENSION!! (and from a business stand point, you will attract a LOT of Magento ppl in the community just with this little extension… but I’m sure you know this already :/ )

  14. Larso March 29, 2010 at 8:41 am #

    Thanx and very well done, but
    “catalog.xml file which is found in the app/design/frontend/X/Y/layout/” does not seem to be there anymore in Magento ver. 1.4.0.1. Or am I wrong ?

  15. Ashley March 29, 2010 at 11:31 am #

    Should be there. The X and Y are place holders for your theme – that may be default and default for example.

  16. Larso March 30, 2010 at 3:40 am #

    ok, found it. i was looking in ‘default’ but the actual folder is called ‘base’ since the upgrade. thanks again.

  17. Paulo Matos April 27, 2010 at 1:43 pm #

    Hi Ashley!

    Seems that you forgot about the file

    X/Y/layout/reports.xml

    to comment the line

    Excelent article.

    Cheers

    Paulo

  18. Paulo Matos April 28, 2010 at 4:45 pm #

    Well the code was wipped out, let me try to escape it… Remove the following line from reports.xml

    <block type=”reports/product_compared” before=”right.permanent.callout” name=”right.reports.product.compared” template=”reports/product_compared.phtml” />

  19. Ashley April 28, 2010 at 7:49 pm #

    Thanks Paulo I updated the post

  20. Chae May 17, 2010 at 7:54 pm #

    Thanks Ashley for the tips above – all worked a treat. You’d think Magento would have these sort of things switched on & off as & when wanted through admin by now.

  21. Ingmar June 29, 2010 at 2:20 pm #

    Thanks Ashley, so easy, even for a goof like me.

  22. DangerMouse August 7, 2010 at 6:03 am #

    Please correct me if I’m wrong – I only installed Magenot this week – but isn’ it good practice to create a new XML file to adjust the layout and use something like:

    I appreciate that this doesn’t remove the functionality just the visual – I’m working on how to do that side of it!

    Cheers,

    Steve

  23. John Galt August 7, 2010 at 2:20 pm #

    “Maybe it’d be nice to make this into a Magento extension, so that it can be enabled and disabled on the admin interface. If there is enough interest in that, I’ll bundle up my code change, it’s really only one file, after all. If you’re after something like that – let me know..”

    I see that several people have responded to your offer quite a while ago, has this ever been made into a one-click extension?

    I am new to Magento, how will these changes impact me if I upgrade to new releases of Magento?

    Thanks.

  24. Ashley August 7, 2010 at 10:14 pm #

    Hi, DangerMouse – WordPress has diligently hosed your XML from the comment I’m afraid. Please flick me an email and I’ll take a look at what you mean.

  25. Ashley August 7, 2010 at 10:16 pm #

    Hi, John – no I haven’t made it an extension, I’ve not really got around to it.

  26. Yigal August 12, 2010 at 1:52 am #

    Thank you!
    That PHP trick is way better than other solutions I found.

  27. Kirsten October 5, 2010 at 8:20 pm #

    Thank you!!! An extension would be amazing for this.

  28. Sahus Pilwal November 29, 2010 at 6:56 am #

    Ash your a life saver. This is by far the best solution to removing the Compare functionality in Magento eCommerce…

  29. Chris December 9, 2010 at 4:58 pm #

    Awesome, work perfectly in 1.4.1.1.

  30. Koffiekoning January 10, 2011 at 2:32 am #

    This might be a nice alternative for removing the sidebar comparison, and other irritating stuff.

    Create a local.xml in layout folder and put this code:

  31. Koffiekoning January 10, 2011 at 2:42 am #

    Hmm, the code isn’t visible in the comments.

    Create a local.xml in layout folder and put this code:

    <default>
         <!-- Remove callouts and rarely used stuff -->
         <remove name="right.poll"/>
         <remove name="paypal.partner.right.logo"/>
         <remove name="catalog.compare.sidebar" />
     </default>
  32. Your Name January 26, 2011 at 9:07 am #

    Koffiekoning, that´s a great tip.

  33. Billy March 12, 2011 at 10:49 am #

    Ashley, I appreciate all your tips. I’m a relative newb but I’ve done this one on another site but when doing it this time I got this error when I tried to open my “Home Page”.
    Fatal error: Method Varien_Object::__tostring() cannot take arguments in /home/cabinets/public_html/dev.dpbe-com.com/magento/lib/Varien/Object.php on line 488
    Any idea what I might have messed up? Thanks

  34. Ashley March 12, 2011 at 4:04 pm #

    @Billy, I think that’s an environment issue for Magento on PHP 5.3, when in doubt, check with Google.

  35. Billy March 12, 2011 at 6:19 pm #

    Thanks Ashley for the quick response. I sorta new in my mind that the two weren’t related. Right after I posted I remembered that my host was working an issue with cron that was the cause of this problem. All your suggestions here worked exactly as stated and “Compare” is gone. Thanks again for putting up with a “newb”!!

  36. Ashley March 12, 2011 at 6:41 pm #

    No worries Billy, we were all new to the internet once upon a time. The old copy-paste the error message into Google before asking for help trick will actually resolve 99.9% of all of your future issues, I cannot recommend it enough.

  37. Irina March 30, 2011 at 2:48 pm #

    Ashley,

    Thanks very much for these instructions – they worked perfect for me as well!

    Thanks for a great effort! And yes, having an extension for that would be great as well :) .

  38. LED April 30, 2011 at 4:27 am #

    This is the best solution for removing the add to compare link that I have found on the net.

    Thanks for explaining it step by step with a solution that won’t make a conflict with future upgrades.

  39. x0backslash0x September 4, 2011 at 11:17 am #

    Great article Ashley. The changes you describe here are still relevant at version 1.5.1.0.

    Except for Compare.php, placing the customized version under either the core directory tree or the local one (or both) does not seem to get rid of the pesky ‘Add to Compare’ links.

  40. tom November 11, 2011 at 3:55 am #

    Very usefull.
    Thank you so much for this.
    magento can be a crime for
    developers but you make life easier.

  41. Eddie January 18, 2012 at 8:50 am #

    Free extension to remove comparison feature:
    http://www.magentocommerce.com/magento-connect/niro/extension/6455/et_advancedcompare

  42. Tom January 29, 2012 at 2:29 am #

    Hi again from Vienna,

    like it a lot!
    but one more question:
    In the category list, the space where the link for add to compare list was remains there – just like an placeholder. With Firebug I could not find a hint where this comes from.
    any idea?

    Thank you
    Tom

Leave a Reply:

Gravatar Image