Files
shopify-storefront/store/index.js
T
2019-09-30 19:48:54 +02:00

23 lines
497 B
JavaScript

export const state = () => ({
products: [],
cart: []
})
export const mutations = {
setProducts (state, data) {
state.products = data
},
addToCart (state, item) {
const element = state.cart.filter(el => el.id === item.id)
if (element.length > 0) {
const index = state.cart.indexOf(element[0])
// eslint-disable-next-line no-console
console.log(index)
state.cart[index].count++
} else {
item.count = 1
state.cart.push(item)
}
}
}