orderiom-api-package 0.4.61 → 0.4.62
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 +45 -57
package/package.json
CHANGED
package/src/modules/product.js
CHANGED
|
@@ -261,6 +261,11 @@ const mutations = {
|
|
|
261
261
|
}
|
|
262
262
|
};
|
|
263
263
|
const actions = {
|
|
264
|
+
chooseCategory({commit, dispatch, state}, {category, restaurantId}){
|
|
265
|
+
commit("setSelectedCategory", category);
|
|
266
|
+
dispatch("getProducts", {category, restaurantId,});
|
|
267
|
+
dispatch("getAttributeItems", {category, restaurantId});
|
|
268
|
+
},
|
|
264
269
|
getCategories({ commit, dispatch, rootState, state }, restaurantId) {
|
|
265
270
|
let basketId = undefined;
|
|
266
271
|
try {
|
|
@@ -270,65 +275,48 @@ const actions = {
|
|
|
270
275
|
} catch(e) {
|
|
271
276
|
console.error("getCategories: " + e);
|
|
272
277
|
}
|
|
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
278
|
|
|
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
|
-
}
|
|
279
|
+
return $http.get("api/restaurant/category", { params: {
|
|
280
|
+
restaurantId,
|
|
281
|
+
basketId
|
|
282
|
+
}}).then(res => {
|
|
283
|
+
let categories = res.data.data;
|
|
316
284
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
285
|
+
$http.get("api/restaurant/category", { params: {
|
|
286
|
+
restaurantId,
|
|
287
|
+
basketId,
|
|
288
|
+
extra: 1,
|
|
289
|
+
}}).then(res => {
|
|
290
|
+
const extraCategories = res.data.data;
|
|
291
|
+
|
|
292
|
+
if (extraCategories.length) commit('setCategories', [...categories, ...extraCategories]);
|
|
293
|
+
else commit('setCategories', categories);
|
|
294
|
+
|
|
295
|
+
if(state.categories.length){
|
|
296
|
+
if(!state.selectedCategory) {
|
|
297
|
+
dispatch('chooseCategory', {
|
|
298
|
+
category: state.categories[0],
|
|
299
|
+
restaurantId
|
|
300
|
+
})
|
|
301
|
+
}else{
|
|
302
|
+
// 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.
|
|
303
|
+
const catInList = categories.find(cat => cat.id === state.selectedCategory.id);
|
|
304
|
+
if(!catInList || JSON.stringify(state.selectedCategory) !== JSON.stringify(catInList)){
|
|
305
|
+
dispatch('chooseCategory', {
|
|
306
|
+
category: state.categories[0],
|
|
307
|
+
restaurantId
|
|
308
|
+
})
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}).catch(
|
|
313
|
+
commonErrorCallback()
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
return res
|
|
317
|
+
}).catch(
|
|
318
|
+
commonErrorCallback()
|
|
319
|
+
);
|
|
332
320
|
},
|
|
333
321
|
getProducts({ commit, state, rootState }, data) {
|
|
334
322
|
commit("setSelectedCategory", data.category);
|