Jump to content

Number of Comparing Products on Category Page


derthis

Recommended Posts

Hi Everyone,

 

Does anybody know how to use ajax to display the actual number of products chosen for comparison?

 

Why? Well, it is kind of confusing when somebody checks a few products to compare them, and then, after a while, he forgets about it, wants to check another product's compare button, and it shouts "You have reached maximum number..".

 

Thanks!

Link to comment
Share on other sites

Hello,

 

You can edit/override the CompareController, modify the preProcess function as to return the number of the selected products in case of a specific ajax request.

 

e.g. have the action parameter in the url be 'getnum'

 

In case the action is getnum, you retrieve the numbers with:

if (Tools::getValue('ajax') AND Tools::getValue('action') == 'getnum')
[indent=1]die(count(CompareProduct::getCompareProducts((int)self::$cookie->id_compare)))[/indent]

 

Then you need to edit products-comparison.js and add to reloadProductComparison:

 

$.ajax({
  url: 'products-comparison.php?ajax=1&action=getnum',
 async: true,
  success: function(data){
   if (data != '0')
   {
	 //YOU HAVE RETRIEVED THE NUMBER OF PRODUCTS, NOW PROCESS THE DATA
   }
  },
   error: function(){
	//EXECUTE IN CASE OF ERROR
   }
  });

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...