I have a menu system in place and I have got some code for the checkout system to identify deals/discounts if certain items show up in the cart. here is the code so far:
var shampoo = false;
var dye = false;
var conditioner = false;
for (var i in cartArray) {
switch (cartArray[i].name) {
case 'Pantene Pro-V':
drinks = true;
break;
case 'Red Dye':
chicken = true;
break;
case 'Herbal Conditioner':
kebab = true;
break;
}
if (shampoo && dye && conditioner) {
console.log("yes");
// shoppingCart.removeItemFromCartAll(cartArray[i].name);
// window.location.reload(true);
break;
}
}
if (!shampoo || !dye || !conditioner) {
console.log("no");
}
The console log shows a yes in a full random cart so thats a positive but i tried to remove these three items together as a group but it doesn't work. heres the code for my remove function above:
obj.removeItemFromCartAll = function(name) {// removes all item name
for (var i in cart) {
if (cart[i].name === name){
cart.splice(i,1);
break;
}
}
saveCart();
};
I tried inserting this code:
shoppingCart.removeItemFromCartAll(cartArray[i].name);
underneath each case but it ends up removing the item individually in the cart, not as a group of three. please help. thank you.
(btw in the end i want to remove these three and add another item into the cart from the menu (like a package that has these three at a reduced price...fyi))
Aucun commentaire:
Enregistrer un commentaire