Shopify Cart Add js to add multiple products

JunaidT
Shopify Partner
10 0 2

I am facing an issue with adding multiple products to the cart using jquery ajax. I am getting multiple ids in the console. I tested the network tab as well and it is showing multiple add requests with a perfect status of 200 but when I refresh the page to view the cart it is showing 1 product and sometimes all get into the cart. I don't know why it is failing sometimes.

 

 $('.radio.selected').each(function( index ) {
  var The_id = $( this ).attr('datacustom_id');
     console.log(The_id);
jQuery.ajax({
  url:'/cart/add.js',
  type: 'post',
  dataType: 'json',
  data: { quantity:1, id: The_id }
  // Optional: success/error functions
})    
     
});   
Replies 2 (2)

JunaidT
Shopify Partner
10 0 2

Screenshot_100.png

 

2 requests with response 200 but some time it adds 2 product in cart and sometime only 1 is added

joshpugh
Shopify Partner
2 0 0

This has been a pretty constant issue for me as well.

Josh Pugh (CEO / fortnight.digital)