3

I am completely at a loss as to how to remove the Add to Compare links in my template. I have done a global search and found every file that contains that phrase and have carefully commented out the section that contains that term in each file. This worked to remove the term from the list view but not from the grid view. Where else could this link be living?

6 Answers 6

0

The recommended way is to use the solution provided below:

https://magento.stackexchange.com/a/4997/695

Quick and dirty way to remove addtocompare links - Not recommended anymore

To remove "Add to Compare" links everywhere in your magento store

  1. Override the Abstract Class "Abstract.php" inside app/code/core/Mage/Catalog/Block/Product to app/code/local/Mage/Catalog/Block/Product

  2. Modify the method getAddToCompareUrl($product) in Abstract.php

    public function getAddToCompareUrl($product)
    {
      return "";
    }
    
5
  • 5
    I think it is really a bad idea to rewrite the Mage_Catalog_Block_Abstract block class just to remove a few links from the templates. Mar 14, 2013 at 7:55
  • @Fabian Blechschmidt yes agreed but.... its better than commenting in each of the template files...bcoz this "add to compare" has been found in 12 template files. The better way is to override the Mage_Catalog_Helper_Product_Compare and modify the function getAddUrl()
    – Haijerome
    Mar 14, 2013 at 11:12
  • 1
    No my opinion :-) But a way to achieve the goal. Mar 14, 2013 at 13:10
  • Agreed with @FabianBlechschmidt . This is a terrible method.
    – pspahn
    Nov 7, 2014 at 22:21
  • Not a good idea if you want to upgrade Magento eventually, diff the files, and re-do your custom changes. Or you can use css to target the element and hide it.
    – DWils
    Dec 11, 2014 at 0:13
8

I propose to create a new custom module ;

Step 1 :

Create the override class

 <?php
    class YourPackage_YourModule_Helper_Product_Compare extends Mage_Catalog_Helper_Product_Compare
    {

        public function getAddUrl($product)
    {
        /* 
         * Configurable from Admin
         * Go to System > Configuration > Catalog: Catalog > Recently Viewed/Compared Products
         * Set “Default Recently Compared Products” count to 0
         * For display compare link you can put a number greater than 0
         */

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

        return false;
    }

    }

Step 2:

Create the rewrite XML

<?xml version="1.0"?>
<config>
    <modules>
        <YourPackage_YourModule>
            <version>1.0</version>
        </YourPackage_YourModule>
    </modules>
    <global>
        <helpers>
            <catalog>
                <rewrite>
                    <product_compare>YourPackage_YourModule_Helper_Product_Compare</product_compare>
                </rewrite>
            </catalog>
        </helpers>
    </global>
</config>

Step 3:

Activate the Module

<?xml version="1.0"?>
<config>
    <modules>
        <YourPackage_YourModule>
            <active>true</active>
            <codePool>local</codePool>
        </YourPackage_YourModule>
    </modules>
</config>

If you like to remove compare Blocks :

<?xml version="1.0" encoding="UTF-8"?>
<layout>
    <default>
        <remove name="catalog.compare.sidebar"/>
        <remove name="right.reports.product.compared"/>
    </default>   
</layout>
2
  • Could you add paths to where the files should be put? Magento devs can usually figure this out, but for people just getting into magento it could be a great help.
    – forsvunnet
    Apr 2, 2014 at 9:34
  • you're right , this article below can help you @forsvunnet [magentocommerce.com/wiki/5_-modules_and_development/0-_module_development_in_magento/custom_module_with_custom_database_table] Apr 2, 2014 at 20:53
2

You can override the Mage_Catalog_Helper_Product_Compare::getAddUrl() method.

Change it to this:

public function getAddUrl($product)
{
    return false;
}
2

Version 1.7.0.2

In order to reduce sweat, feed your local.css file instead.

First, add style to the add-to-links <div>:

    .add-to-links {display: none}

Notice that you also removed the vertical line between the Add to Wishlist and Add to Compare link.

Next, we continue to style your theme's local.css and hide <div> or in the Product View display:

    .add-to-box .or {display: none}

If you now refresh the frontend of your sandbox store, you'll see these changes take effect.

1

Okay, one of the files - list.phtml - had two instances of this. To remove it you need to find all of the blocks that look like:

                <ul class="add-to-links">
                    <?php if ($this->helper('wishlist')->isAllow()) : ?>
                        <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
                    <?php endif; ?>
                    <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                        <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
                    <?php endif; ?>
                </ul>

and add

<!--

above, and

-->

below them, thus commenting them out.

2
  • 4
    Better use <?php */ */ ?> instead if the <!-- and -->, so the code is not delivered to the browser. Mar 14, 2013 at 7:55
  • First the template should be copied to a custom theme ...
    – Alex
    Jun 21, 2013 at 21:50
1

I'm not affiliated with this extension in any way but have used it and it does the trick perfectly. Search Magento connect for ET Advanced Compare. (http://www.magentocommerce.com/magento-connect/et-advanced-compare.html)

It can remove the add to compare function completely but also gives you the option to add products to compare using Ajax, negating the need to reload the page when a user adds to compare.

Your Answer

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

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