|
@@ -1,18 +1,23 @@
|
|
|
const state = {
|
|
|
products: [],
|
|
|
- filtered: [],
|
|
|
+ filteredProducts: [],
|
|
|
+ filteredVariants: [],
|
|
|
selectedProduct: null
|
|
|
}
|
|
|
|
|
|
const getters = {
|
|
|
getProducts (state) {
|
|
|
- return state.filtered.length === 0 ? state.products : state.filtered
|
|
|
+ return state.filteredProducts.length === 0 ? state.products : state.filtered
|
|
|
},
|
|
|
getSelectedProduct(state) {
|
|
|
return state.selectedProduct
|
|
|
},
|
|
|
getVariants(state) {
|
|
|
- return !!state.selectedProduct ? state.selectedProduct.variants : []
|
|
|
+ if (!!state.selectedProduct) {
|
|
|
+ return state.filteredVariants.length === 0 ? state.selectedProduct.variants : state.filteredVariants
|
|
|
+ }
|
|
|
+
|
|
|
+ return []
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -24,8 +29,12 @@ const mutations = {
|
|
|
state.selectedProduct = payload.product
|
|
|
},
|
|
|
applyProductsFilter(state, payload) {
|
|
|
- state.filtered = payload
|
|
|
+ state.filteredProducts = payload
|
|
|
+ },
|
|
|
+ applyVariantsFilter(state, payload) {
|
|
|
+ state.filteredVariants = payload
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
const actions = {
|
|
@@ -70,6 +79,9 @@ const actions = {
|
|
|
},
|
|
|
filterProducts({ commit }, payload) {
|
|
|
commit('applyProductsFilter', payload)
|
|
|
+ },
|
|
|
+ filterVariants({ commit }, payload) {
|
|
|
+ commit('applyVariantsFilter', payload)
|
|
|
}
|
|
|
}
|
|
|
|