Skip to content

Commit

Permalink
[ft #161868040] functions to enable showing cart items and remove a c…
Browse files Browse the repository at this point in the history
…art item
  • Loading branch information
Easybuoy committed Nov 12, 2018
1 parent 905dbbc commit d927508
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions client/js/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const showCart = () => {
let carttablebody = document.getElementById('carttablebody');
let output = '';

console.log(cartItems)
// check if cart is empty
if (cartItems === null) {
return alert('Cart Is Empty');
Expand All @@ -52,17 +51,15 @@ const showCart = () => {
}

const removeProductFromCart = (productId) => {
let cartItems = JSON.parse(localStorage.getItem('products'));
cartItems.map((item, i) => {
console.log(i)
console.log(item)
let cartItems = JSON.parse(localStorage.getItem('products'));
cartItems.map((item, i) => {
if (item.productId === productId) {
cartItems.splice(i, 1);

if (item.productId === productId) { console.log('entered')
cartItems.splice(i, 1);
// delete cartItems[i];
console.log(cartItems);
}
})
localStorage.setItem('products', JSON.stringify(cartItems));
}
});
window.location.reload();
}

// This function appends the total item in cart to the cart image on the frontend
Expand Down

0 comments on commit d927508

Please sign in to comment.