diff --git a/store/index.js b/store/index.js index f90f36a..abaf333 100644 --- a/store/index.js +++ b/store/index.js @@ -31,14 +31,10 @@ export const mutations = { ;(state.cart = []), (state.cartUIStatus = "idle") }, addToCart: (state, payload) => { - let itemfound = false - state.cart.forEach(el => { - if (el.id === payload.id) { - el.quantity += payload.quantity - itemfound = true - } - }) - if (!itemfound) state.cart.push(payload) + let itemfound = state.cart.find(el => el.id === payload.id) + itemfound + ? (itemfound.quantity += payload.quantity) + : state.cart.push(payload) } }