This repository has been archived on 2021-09-06. You can view files and clone it, but cannot push or open issues or pull requests.
2021-05-05 15:41:12 +02:00
|
|
|
export default {
|
|
|
|
addProductToCart(state, productData) {
|
|
|
|
const productInCartIndex = state.items.findIndex(
|
|
|
|
ci => ci.productId === productData.id
|
|
|
|
);
|
|
|
|
|
|
|
|
if (productInCartIndex >= 0) {
|
|
|
|
state.items[productInCartIndex].qty++;
|
|
|
|
} else {
|
|
|
|
const newItem = {
|
|
|
|
productId: productData.id,
|
|
|
|
title: productData.title,
|
|
|
|
image: productData.image,
|
|
|
|
price: productData.price,
|
|
|
|
qty: 1
|
|
|
|
};
|
|
|
|
state.items.push(newItem);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
removeProductFromCart(state, prodId) {
|
|
|
|
const productInCartIndex = state.items.findIndex(
|
|
|
|
cartItem => cartItem.productId === prodId
|
|
|
|
);
|
|
|
|
state.items.splice(productInCartIndex, 1);
|
2021-05-05 16:30:00 +02:00
|
|
|
}
|
2021-05-05 15:41:12 +02:00
|
|
|
};
|