kapastratos Posted October 12, 2013 Share Posted October 12, 2013 (edited) Hello, I am working on my website and I have run into a little problem. Data to use: product id 1 - attributes combination id 2product 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 October 19, 2013 by kapastratos (see edit history) Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted October 14, 2013 Share Posted October 14, 2013 You should defining the additional id_combination value to be added. $('#idCombination').val() will return the same value (the selected combination) Link to comment Share on other sites More sharing options...
kapastratos Posted October 19, 2013 Author Share Posted October 19, 2013 You should defining the additional id_combination value to be added. $('#idCombination').val() will return the same value (the selected combination) That is not a problem (I edited the post above with idCombination2), my problem still persists! Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted October 20, 2013 Share Posted October 20, 2013 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 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now