cleanout some code
This commit is contained in:
parent
000139b9ae
commit
787b44dc13
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -6,8 +6,7 @@ export default {
|
|||
namespaced: true,
|
||||
state() {
|
||||
return {
|
||||
items: [],
|
||||
qty: 0
|
||||
items: []
|
||||
};
|
||||
},
|
||||
actions: cartActions,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
Reference in New Issue