Pergunta

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?

Foi útil?

Solução

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 "";
    }
    

Outras dicas

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>

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

Change it to this:

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

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.

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.

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top