From 2e7da5ab02ffa8b07fede7f6cd7e5dbbd90fac5f Mon Sep 17 00:00:00 2001 From: "Adam T. Carpenter" Date: Mon, 23 Nov 2020 17:29:58 -0500 Subject: finished up product detail functionality, started checkout and cart views --- iridescence/src/store/index.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'iridescence/src/store') diff --git a/iridescence/src/store/index.js b/iridescence/src/store/index.js index dabcf31..8208f35 100644 --- a/iridescence/src/store/index.js +++ b/iridescence/src/store/index.js @@ -10,17 +10,12 @@ export default new Vuex.Store({ state: { searchTerm: "", products: [], + cart: {}, busy: false, compare: a => (a.featured ? -1 : 1), productDetailId: 0 }, getters: { - busy(state) { - return state.busy; - }, - productDetailId(state) { - return state.productDetailId; - }, products(state) { return state.products .filter(item => { @@ -38,6 +33,20 @@ export default new Vuex.Store({ productDetailId(state, id) { state.productDetailId = id; }, + cartItem(state, { id, by }) { + if (state.cart[id]) { + let newCount = (state.cart[id] += by); + state.cart = { + ...state.cart, + [id]: newCount + }; + } else { + state.cart = { + ...state.cart, + [id]: 1 + }; + } + }, compare(state, compare) { state.compare = compare; }, @@ -75,6 +84,5 @@ export default new Vuex.Store({ commit("toggleBusy"); return photoSet; } - }, - modules: {} + } }); -- cgit v1.2.3