|
@@ -1,11 +1,12 @@
|
|
|
const state = {
|
|
|
products: [],
|
|
|
+ filtered: [],
|
|
|
selectedProduct: null
|
|
|
}
|
|
|
|
|
|
const getters = {
|
|
|
getProducts (state) {
|
|
|
- return state.products
|
|
|
+ return state.filtered.length === 0 ? state.products : state.filtered
|
|
|
},
|
|
|
getSelectedProduct(state) {
|
|
|
return state.selectedProduct
|
|
@@ -22,10 +23,8 @@ const mutations = {
|
|
|
setSelectedProduct(state, payload) {
|
|
|
state.selectedProduct = payload.product
|
|
|
},
|
|
|
- applyFilter(state, payload) {
|
|
|
- if (!payload.constraint) {
|
|
|
- return
|
|
|
- }
|
|
|
+ applyProductsFilter(state, payload) {
|
|
|
+ state.filtered = payload
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -61,8 +60,6 @@ const actions = {
|
|
|
}
|
|
|
},
|
|
|
selectVariant({ commit, dispatch }, payload) {
|
|
|
- console.log(payload)
|
|
|
-
|
|
|
commit('setSelectedProduct', {
|
|
|
product: null
|
|
|
})
|
|
@@ -70,6 +67,9 @@ const actions = {
|
|
|
dispatch('addToCart', {
|
|
|
product: payload.data
|
|
|
})
|
|
|
+ },
|
|
|
+ filterProducts({ commit }, payload) {
|
|
|
+ commit('applyProductsFilter', payload)
|
|
|
}
|
|
|
}
|
|
|
|