How to Remove Add to Compare

Last modified by nikola99 on Thu, June 24, 2010 16:56
Source|Old Revisions  

This is an old revision of the document!


Removing the Add to Compare feature from Magento is not as easy as it should be. Whereas the Wishlist can be simply and explicitly disabled in Admin > Config > System, no such disabling mechanism exists for Add to Compare. This article explains an effective way for disabling Add to Compare and provides a reference for files to edit.


As with most things Magento, there are a number of ways to accomplish the task of removing the Add to Cart feature. A quick review of the standard templates reveals the following code from catalog/product/view/addto.phtml:

  1. <?php
  2. // snip
  3. <?php if($_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product) ): ?>
  4.     <li><span class="pipe">|</span> <a href="<?php echo $_compareUrl ?>"><?php echo $this->__('Add to Compare') ?></a></li>
  5. <?php endif; ?>
  6. // snip
  7. ?>

This is the convention that Varien have taken - assign the return value of getAddUrl and if it’s not null, echo the result. This presents a simple solution vector: make that function return false. This is easy to do by overriding Mage_Catalog_Helper_Product_Compare.

Making the Module

In this example the module is namespaced under BlueAcorn. Feel free to adjust folders, files, and references as necessary.

Create the override class

Create app/code/local/BlueAcorn/Catalog/Helper/Product/Compare.php

  1. <?php
  2. /**
  3. * @category   Mage
  4. * @package    Mage_Catalog
  5. * @author     Ben Marks, Blue Acorn LLC
  6. */
  7. class BlueAcorn_Catalog_Helper_Product_Compare extends Mage_Catalog_Helper_Product_Compare
  8. {
  10.     /**
  11.      * Retrieve url for adding product to conpare list, return false
  12.      *
  13.      * @param   Mage_Catalog_Model_Product $product - not used but must leave else we get errors
  14.      * @return  boolean false
  15.      */
  16.     public function getAddUrl($product)
  17.     {
  18.         return false;
  19.     }
  21. }
  22. ?>

If you want to be able to toggle the setting per site

If you want to be able to toggle the setting per site add this before “return false”:

  1. if(Mage::getStoreConfig('catalog/recently_products/compared_count')) {
  2.     return parent::getAddUrl($product);
  3. }

Now, to turn of product comparison:

  1. Go to System > Configuration > Catalog: Catalog > Recently Viewed/Compared Products
  2. Set “Default Recently Compared Products” count to 0

Create the rewrite xml

Create app/code/local/BlueAcorn/Catalog/etc/config.xml

  1. <?xml version="1.0"?>
  2. <config>
  3.     <modules>
  4.         <BlueAcorn_Catalog>
  5.             <version>1.0</version>
  6.         </BlueAcorn_Catalog>
  7.     </modules>
  8.     <global>
  9.         <helpers>
  10.             <catalog>
  11.                 <rewrite>
  12.                     <product_compare>BlueAcorn_Catalog_Helper_Product_Compare</product_compare>
  13.                 </rewrite>
  14.             </catalog>
  15.         </helpers>
  16.     </global>
  17. </config>

Activate the Module

create app/etc/modules/BlueAcorn_Catalog.xml

  1. <?xml version="1.0"?>
  2. <config>
  3.     <modules>
  4.         <BlueAcorn_Catalog>
  5.             <active>true</active>
  6.             <codePool>local</codePool>
  7.         </BlueAcorn_Catalog>
  8.     </modules>
  9. </config>

That’s it. Refresh the cache and the Add to Compare should be gone.

Test and Clean-up

Verify that the class is working. Also, non-standard templates may not reference the helper in the same way as Varien, so it is wise to manually verify that Add to Compare no longer appears.

To thoroughly dismiss compare from the site, the following edits can be made in the appropriate design/frontend layout folder (referring to out-of-box templates). If there is a possibility that the feature will need to be restored down the road, then skip these edits.

  • bundle.xml:
  • - Remove entire <catalog_product_compare_index> node
  • reports.xml:
  • - <default><reference name=”right”> Remove <block type=”reports/product_compared” before=”right.permanent.callout” name=”right.reports.product.compared” template=”reports/product_compared.phtml” />
  • catalog.xml:
  • - <default><reference name=”right”> Remove <block type=”core/template” before=”cart_sidebar” name=”” template=”catalog/product/compare/sidebar.phtml”/>
  • - Remove entire <catalog_product_compare_index> node
  • - Remove entire <customer_account_index> node
  • customer.xml:
  • - <customer_account><reference name=”left”> Remove <block type=”core/template” name=”” template=”catalog/product/compare/sidebar.phtml”/>


The result of this should be the an authoritative, best-practice removal of the Add to Compare feature.