Jump to content

Adding 2 products from product page


kapastratos

Recommended Posts

Hello,
 
I am working on my website and I have run into a little problem.
 
Data to use:
 
product id 1 - attributes combination id 2
product id 1 - attributes combination id 3
 
Default prestashop behavior: when a customer hit the "add to cart" button from product page, product id 1 is added to cart with combination id 2
 
What I want: when a customer hit the "add to cart" button from product page, product id 1 is added to cart with combination id 2 AND product id 1 is added to cart with combination id 3
 
I did id, but it is not working very good.
 
The main problem is that sometimes when I hit the add to cart button I have 2 products in cart and sometimes I have just one and when I refresh the page, there are 2 products...so my first idea was that I missed something or did something wrong but no, it seems that also on default prestashop version I have the same problem!
 
I had to setup a fresh prestashop 1.5.6.0 version on a remote server and after adding one single line to ajax-cart.js it has the same behavior.
 
Note: I added one single line to ajax-cart.js (modules/blockcart/ajax-cart.js) @ line 43

 

Original:

		//for product page 'add' button...
		$('#add_to_cart input').unbind('click').click(function(){
			ajaxCart.add( $('#product_page_product_id').val(), $('#idCombination').val(), true, null, $('#quantity_wanted').val(), null);
			return false;
		});

To:

		//for product page 'add' button...
		$('#add_to_cart input').unbind('click').click(function(){
			ajaxCart.add( $('#product_page_product_id').val(), $('#idCombination').val(), true, null, $('#quantity_wanted').val(), null);
			ajaxCart.add( $('#product_page_product_id').val(), $('#idCombination2').val(), true, null, $('#quantity_wanted2').val(), null);
			return false;
		});

You can test it here:

 

http://www.myopticshop.com/en/music-ipods/1-ipod-nano.html

 

Just add a product to the cart and it will add 2 if you hit again it will add another 2 and so on...but sometimes it adds just one and after you refresh the page the product it`s there...and sometimes not!

Sometimes if you just delete the product from the cart (upper right) and click on add to cart again...it adds just one...sometimes 2...I think you get the point...sorry!

 

 

Again, this is a fresh ps 1.5.6.0 no modification, just 1 single line to ajax-cart.js

 

Any ideas what is wrong?

 

Thank you

Edited by kapastratos (see edit history)
Link to comment
Share on other sites

Then you don't understand what i mean ...
idCombination is a parameter (id) which referring to an element to get the value.
You can't just add the new id like idCombination2 inside ajaxCart.add() function :P

 

I can add 2 product at once and don't have a problem after doing a simple modification in ajax-cart.js like this :

//for product page 'add' button...
$('#add_to_cart input').unbind('click').click(function(){
    // First, define the selected combination
    selComb = parseInt($('#idCombination').val());
    // Then define the second combination
    newComb = selComb+1;
    // Now run the function ajaxCart.add() for both
    // First we add the selected product
    ajaxCart.add( $('#product_page_product_id').val(), $('#idCombination').val(), true, null, $('#quantity_wanted').val(), null);
    // Then we add the second product (if the first selected combination is the last id then this fucntion will add the same product twice)
    ajaxCart.add( $('#product_page_product_id').val(), newComb, true, null, $('#quantity_wanted').val(), null);
    return false;
});

NOTE:

This is just an example!

The second product/combination to be added, should be precisely defined to get the desired end result.

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...