product page and cart finished

This commit is contained in:
thomas
2020-02-25 20:14:23 +01:00
parent ef8c22855f
commit bbca265dea
12 changed files with 198 additions and 115 deletions
+3 -29
View File
@@ -1,7 +1,8 @@
export const state = () => ({
products: [],
cart: [],
checkout: {}
checkout: {
lineItems: []
}
})
export const mutations = {
@@ -10,32 +11,5 @@ export const mutations = {
},
setCheckout (state, data) {
state.checkout = data
},
incrementCart (state, index) {
state.cart[index].count++
},
addCart (state, item) {
item.count = 1
state.cart.push(item)
}
}
export const getters = {
getCartItem: state => (id) => {
return state.cart.filter(item => (item.id === id))
}
}
export const actions = {
addItemToCart ({ commit, getters, state }, payload) {
return new Promise((resolve) => {
const element = getters.getCartItem(payload.id)
if (element.length > 0) {
commit('incrementCart', state.cart.indexOf(element[0]))
} else {
commit('addCart', payload)
}
resolve(getters.getCartItem(payload.id)[0])
})
}
}