How to Remove Add to Compare
This is an old revision of the document!
Introduction |
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.
Method |
As with most things Magento, there are a number of ways to accomplish the task of removing the Add to Compare feature. A quick review of the standard templates reveals the following code from catalog/product/view/addto.phtml:
- <?php
- // snip
- <?php if($_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product) ): ?>
- <li><span class="pipe">|</span> <a href="<?php echo $_compareUrl ?>"><?php echo $this->__('Add to Compare') ?></a></li>
- <?php endif; ?>
- // snip
- ?>
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
- <?php
- /**
- * @category Mage
- * @package Mage_Catalog
- * @author Ben Marks, Blue Acorn LLC
- */
- class BlueAcorn_Catalog_Helper_Product_Compare extends Mage_Catalog_Helper_Product_Compare
- {
- /**
- * Retrieve url for adding product to conpare list, return false
- *
- * @param Mage_Catalog_Model_Product $product - not used but must leave else we get errors
- * @return boolean false
- */
- public function getAddUrl($product)
- {
- return false;
- }
- }
- ?>
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”:
- if(Mage::getStoreConfig('catalog/recently_products/compared_count')) {
- return parent::getAddUrl($product);
- }
Now, to turn of product comparison:
- Go to System > Configuration > Catalog: Catalog > Recently Viewed/Compared Products
- Set “Default Recently Compared Products” count to 0
Create the rewrite xml |
Create app/code/local/BlueAcorn/Catalog/etc/config.xml
- <?xml version="1.0"?>
- <config>
- <modules>
- <BlueAcorn_Catalog>
- <version>1.0</version>
- </BlueAcorn_Catalog>
- </modules>
- <global>
- <helpers>
- <catalog>
- <rewrite>
- <product_compare>BlueAcorn_Catalog_Helper_Product_Compare</product_compare>
- </rewrite>
- </catalog>
- </helpers>
- </global>
- </config>
Activate the Module |
create app/etc/modules/BlueAcorn_Catalog.xml
- <?xml version="1.0"?>
- <config>
- <modules>
- <BlueAcorn_Catalog>
- <active>true</active>
- <codePool>local</codePool>
- </BlueAcorn_Catalog>
- </modules>
- </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=”catalog.compare.sidebar” 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=”catalog.compare.sidebar” template=”catalog/product/compare/sidebar.phtml”/>
Conclusion |
The result of this should be the an authoritative, best-practice removal of the Add to Compare feature.

