cleanout some code

This commit is contained in:
Andreas Zweili 2021-05-05 16:56:29 +02:00
parent 000139b9ae
commit 787b44dc13
3 changed files with 9 additions and 9 deletions

View File

@ -1,6 +1,10 @@
export default {
quantity(state) {
return state.qty;
var itemsInCart = 0;
state.items.forEach(item => {
itemsInCart = itemsInCart + item.qty;
});
return itemsInCart;
},
items(state) {
return state.items;
@ -8,7 +12,9 @@ export default {
total(state) {
var total = 0;
state.items.forEach(item => {
total = total + item.price;
var itemTotal = 0;
itemTotal = item.price * item.qty;
total = total + itemTotal;
});
return total.toFixed(2);
}

View File

@ -6,8 +6,7 @@ export default {
namespaced: true,
state() {
return {
items: [],
qty: 0
items: []
};
},
actions: cartActions,

View File

@ -16,17 +16,12 @@ export default {
};
state.items.push(newItem);
}
state.qty++;
state.total += productData.price;
},
removeProductFromCart(state, prodId) {
const productInCartIndex = state.items.findIndex(
cartItem => cartItem.productId === prodId
);
const prodData = state.items[productInCartIndex];
state.items.splice(productInCartIndex, 1);
state.qty -= prodData.qty;
state.total -= prodData.price * prodData.qty;
}
};