Hi community,
I coded a button “bundle add to cart” to add 2 products (of bundle) in the cart, but it doesn’t work! It added only 1 product to the cart! but the console shows me 2 calls!
this is the HTML in the cart drawer:
// for every bundle product
//out of the loop
and this is the JS:
$('#csbundle-button').click(function(addItemtoCart) {
$.each($('.cross-check'),function(i,v){
var id = $(this).val();
let addData = {
'id': id,
'quantity': 1
};
fetch('/cart/add.js', {
method: 'POST',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest'
},
body: JSON.stringify(addData)
}).then(function (data) {
if (data.status == 200) {
window.location.refresh;
return
}
else {
console.log('Request returned an error', data)
};
})
.catch(function (error) {
console.log('Request failed', error);
});
window.onerror = function(message, file, line) {
console.log('An error occured at line ' + line + ' of ' + file + ': ' + message);
};
});
});