Create A small extension for the requirement
Create a file:
app/code/local/Sushant/Catalog/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Sushant_Catalog>
<version>0.1</version>
</Sushant_Catalog>
</modules>
<frontend>
<events>
<catalog_product_compare_add_product>
<observers>
<Sushant_Catalog>
<type>singleton</type>
<class>Sushant_Catalog_Helper_Observer</class>
<method>limitProductCompare</method>
</Sushant_Catalog>
</observers>
</catalog_product_compare_add_product>
</events>
</frontend>
</config>
Helper:
app/code/local/Sushant/Catalog/Helper/Observer.php
<?php
class Sushant_Catalog_Helper_Observer extends Mage_Catalog_Model_Product_Compare_List {
/* The limit you want Ex. : 3 */
const COMPARE_LIMIT = 3;
function limitProductCompare($event) {
if (Mage::helper('catalog/product_compare')->getItemCount()<self::COMPARE_LIMIT) return;
$session = Mage::getSingleton('catalog/session');
Mage::getSingleton('catalog/product_compare_list')->removeProduct($event->getProduct());
$session->getMessages()->clear();
Mage::getSingleton('core/session')->addError('You can not compare more than three products to compare. Remove one and try again.');
}
}
Enable Your module :
<?xml version="1.0"?>
<config>
<modules>
<Sushant_Catalog>
<active>true</active>
<codePool>local</codePool>
</Sushant_Catalog>
</modules>
</config>
![]()
2 Comments
Swati · July 2, 2016 at 12:38 pm
it is working but message will display after page refreshing and 4th product not added in list but showing adding comparison process please help to solve this problem
Swati · July 2, 2016 at 12:42 pm
it is working but when adding 4th product it shows message after page refreshing. and at the time of adding 4th product this shows the adding comapsron process but i dont want to shows this process at the time of adding 4th product. so please help to solve this problem