orderiom-api-package 0.4.61 → 0.4.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/modules/product.js +54 -57
package/package.json
CHANGED
package/src/modules/product.js
CHANGED
|
@@ -30,11 +30,15 @@ const state = () => ({
|
|
|
30
30
|
pinnedProducts: null,
|
|
31
31
|
showPinnedProducts: false,
|
|
32
32
|
fetchingProducts: false,
|
|
33
|
+
categoriesFetchedOnce: false,
|
|
33
34
|
});
|
|
34
35
|
const getters = {
|
|
35
36
|
fetchingProducts(state){
|
|
36
37
|
return !!state.fetchingProducts;
|
|
37
38
|
},
|
|
39
|
+
categoriesFetchedOnce(){
|
|
40
|
+
return !!state.categoriesFetchedOnce;
|
|
41
|
+
},
|
|
38
42
|
subCategories(state){
|
|
39
43
|
if(!state.products) return []
|
|
40
44
|
if(state.showPinnedProducts) {
|
|
@@ -158,6 +162,9 @@ const getters = {
|
|
|
158
162
|
}
|
|
159
163
|
}
|
|
160
164
|
const mutations = {
|
|
165
|
+
setCategoriesFetchedOnce(state){
|
|
166
|
+
state.setCategoriesFetchedOnce = true;
|
|
167
|
+
},
|
|
161
168
|
setFetchingProducts(state, isFetching){
|
|
162
169
|
state.fetchingProducts = isFetching;
|
|
163
170
|
},
|
|
@@ -261,6 +268,11 @@ const mutations = {
|
|
|
261
268
|
}
|
|
262
269
|
};
|
|
263
270
|
const actions = {
|
|
271
|
+
chooseCategory({commit, dispatch, state}, {category, restaurantId}){
|
|
272
|
+
commit("setSelectedCategory", category);
|
|
273
|
+
dispatch("getProducts", {category, restaurantId,});
|
|
274
|
+
dispatch("getAttributeItems", {category, restaurantId});
|
|
275
|
+
},
|
|
264
276
|
getCategories({ commit, dispatch, rootState, state }, restaurantId) {
|
|
265
277
|
let basketId = undefined;
|
|
266
278
|
try {
|
|
@@ -270,65 +282,50 @@ const actions = {
|
|
|
270
282
|
} catch(e) {
|
|
271
283
|
console.error("getCategories: " + e);
|
|
272
284
|
}
|
|
273
|
-
return $http
|
|
274
|
-
.get("api/restaurant/category", { params: { restaurantId: restaurantId, basketId: basketId } })
|
|
275
|
-
.then((res) => {
|
|
276
|
-
let categories = res.data.data;
|
|
277
|
-
//TODO: why calling an api write after another while we can do it together?
|
|
278
|
-
//TODO: this api call returns empty on restaurant refresh
|
|
279
|
-
$http
|
|
280
|
-
.get("api/restaurant/category", { params: { restaurantId: restaurantId, extra: 1, basketId: basketId } })
|
|
281
|
-
.then((res) => {
|
|
282
|
-
if (res.data.data.length) {
|
|
283
|
-
categories = [...categories, ...res.data.data];
|
|
284
|
-
commit('setCategories', categories);
|
|
285
|
-
if(categories.length){
|
|
286
|
-
if(!state.selectedCategory) {
|
|
287
|
-
commit("setSelectedCategory", categories[0]);
|
|
288
|
-
}else{
|
|
289
|
-
const catInList = categories.find(cat => cat.id === state.selectedCategory.id);
|
|
290
|
-
if(!catInList || JSON.stringify(state.selectedCategory) !== JSON.stringify(catInList)){
|
|
291
|
-
commit("setSelectedCategory", categories[0]);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
285
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
category: state.selectedCategory,
|
|
302
|
-
restaurantId
|
|
303
|
-
});
|
|
304
|
-
} else {
|
|
305
|
-
commit('setCategories', categories);
|
|
306
|
-
if(categories.length){
|
|
307
|
-
if(!state.selectedCategory) {
|
|
308
|
-
commit("setSelectedCategory", categories[0]);
|
|
309
|
-
}else{
|
|
310
|
-
const catInList = categories.find(cat => cat.id === state.selectedCategory.id);
|
|
311
|
-
if(!catInList || JSON.stringify(state.selectedCategory) !== JSON.stringify(catInList)){
|
|
312
|
-
commit("setSelectedCategory", categories[0]);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
286
|
+
return $http.get("api/restaurant/category", { params: {
|
|
287
|
+
restaurantId,
|
|
288
|
+
basketId
|
|
289
|
+
}}).then(res => {
|
|
290
|
+
let categories = res.data.data;
|
|
316
291
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
292
|
+
$http.get("api/restaurant/category", { params: {
|
|
293
|
+
restaurantId,
|
|
294
|
+
basketId,
|
|
295
|
+
extra: 1,
|
|
296
|
+
}}).then(res => {
|
|
297
|
+
const extraCategories = res.data.data;
|
|
298
|
+
|
|
299
|
+
if (extraCategories.length) commit('setCategories', [...categories, ...extraCategories]);
|
|
300
|
+
else commit('setCategories', categories);
|
|
301
|
+
|
|
302
|
+
if(state.categories.length){
|
|
303
|
+
if(!state.selectedCategory) {
|
|
304
|
+
dispatch('chooseCategory', {
|
|
305
|
+
category: state.categories[0],
|
|
306
|
+
restaurantId
|
|
307
|
+
})
|
|
308
|
+
}else{
|
|
309
|
+
// if selected category is set then check if it is the same category. If it is the same then there is no need to do anything.
|
|
310
|
+
const catInList = categories.find(cat => cat.id === state.selectedCategory.id);
|
|
311
|
+
if(!catInList || JSON.stringify(state.selectedCategory) !== JSON.stringify(catInList)){
|
|
312
|
+
dispatch('chooseCategory', {
|
|
313
|
+
category: state.categories[0],
|
|
314
|
+
restaurantId
|
|
315
|
+
})
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}).catch(
|
|
320
|
+
commonErrorCallback()
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
return res
|
|
324
|
+
}).catch(
|
|
325
|
+
commonErrorCallback()
|
|
326
|
+
).finally(() => {
|
|
327
|
+
commit('setCategoriesFetchedOnce');
|
|
328
|
+
});
|
|
332
329
|
},
|
|
333
330
|
getProducts({ commit, state, rootState }, data) {
|
|
334
331
|
commit("setSelectedCategory", data.category);
|