It seems too cumbersome for the user to have to wait for a page reload everytime they click on "add to compare" to add a product to a compare list and I wanted to change thelink with a checkbox and then add a button that will submit the list of products to compare and then send you to that page.
What is the best way to do this?
Edit:
I will post the code I used so that someone else can use it in the future!
In each product I have a checkbox like this:
<input class="idcompare" type="checkbox" name="idcompare<?php echo $_product->getId();?>" value="<?php echo $_product->getId();?>">Compare
Then I have my form with the button that will send me to the compare page:
<form id="comparelist">
<button type="button" title="<?php echo $this->__('Compare') ?>" class="button"><span><span><?php echo $this->__('Compare') ?></span></span></button>
</form>
And my js that will change the action and submit the form! (not very elegant I know but it works):
jQuery(document).ready(function() {
jQuery('#comparelist .button').click(function(){
var i=0;
var prdString="";
var prdString = jQuery.map(jQuery(':checkbox:checked'), function(n, i){
return n.value;
}).join(',');
var url='<?php echo Mage::getUrl('catalog/product_compare/index').'items/'; ?>'+ prdString + '/uenc/';
jQuery('#comparelist').attr('action', url);
jQuery('#comparelist').submit();
});
});
Best Answer
In order to add a product to compare you need the following url:
You can add multiple items to compare at the same time by creating a comma seperated string of the product id's.
It would look something like this:
Based on this information you can set this up with checkboxes by doing the following:
<form>
id
of each checkbox to the id of the productid
to a comma separated sringonSubmit
have theform action
go here: