orderiom-api-package 0.4.79 → 0.4.81
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 +76 -5
package/package.json
CHANGED
package/src/modules/product.js
CHANGED
|
@@ -31,7 +31,8 @@ const state = () => ({
|
|
|
31
31
|
showPinnedProducts: false,
|
|
32
32
|
fetchingProducts: false,
|
|
33
33
|
categoriesFetchedOnce: false,
|
|
34
|
-
pinnedProductsFetchedOnce: false
|
|
34
|
+
pinnedProductsFetchedOnce: false,
|
|
35
|
+
fetchingProductsHappyHour: false,
|
|
35
36
|
});
|
|
36
37
|
const getters = {
|
|
37
38
|
fetchingProducts(state){
|
|
@@ -39,7 +40,7 @@ const getters = {
|
|
|
39
40
|
},
|
|
40
41
|
subCategories(state){
|
|
41
42
|
if(state.showPinnedProducts) {
|
|
42
|
-
if(state.pinnedProducts
|
|
43
|
+
if(state.pinnedProducts && state.pinnedProducts.length){
|
|
43
44
|
return [{
|
|
44
45
|
id: null,
|
|
45
46
|
imagePath:null,
|
|
@@ -50,7 +51,7 @@ const getters = {
|
|
|
50
51
|
return []
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
|
-
if(!state.products
|
|
54
|
+
if(!state.products || !state.products.length) return [];
|
|
54
55
|
const subCategories = [];
|
|
55
56
|
const ids = Array.from(new Set(state.products.map(productInCategory=>
|
|
56
57
|
productInCategory.subcategory_id
|
|
@@ -270,6 +271,9 @@ const mutations = {
|
|
|
270
271
|
},
|
|
271
272
|
setSubCategories(state , subCategories){
|
|
272
273
|
state.subCategories = subCategories;
|
|
274
|
+
},
|
|
275
|
+
setFetchingProductsHappyHour(state, value){
|
|
276
|
+
state.fetchingProductsHappyHour = value;
|
|
273
277
|
}
|
|
274
278
|
};
|
|
275
279
|
const actions = {
|
|
@@ -321,7 +325,7 @@ const actions = {
|
|
|
321
325
|
commonErrorCallback()
|
|
322
326
|
);
|
|
323
327
|
},
|
|
324
|
-
getProducts({ commit, state, rootState }, data) {
|
|
328
|
+
getProducts({ commit, dispatch, state, rootState }, data) {
|
|
325
329
|
commit("setSelectedCategory", data.category);
|
|
326
330
|
let basketId = undefined;
|
|
327
331
|
try {
|
|
@@ -352,6 +356,8 @@ const actions = {
|
|
|
352
356
|
}
|
|
353
357
|
}).then(res => {
|
|
354
358
|
res.data.data.forEach(productInCategory => {
|
|
359
|
+
productInCategory.happyHours = [];
|
|
360
|
+
|
|
355
361
|
let quantity = 0;
|
|
356
362
|
state.ShoppingCart
|
|
357
363
|
.filter(itemInCart => Number(itemInCart.RestaurantProductId) === Number(productInCategory.id))
|
|
@@ -359,6 +365,11 @@ const actions = {
|
|
|
359
365
|
productInCategory.quantity = quantity;
|
|
360
366
|
});
|
|
361
367
|
commit("setProduct", res.data.data);
|
|
368
|
+
|
|
369
|
+
if(rootState.orderiomApiPackage.restaurant.restaurantInfo.ignore_pre_order_timing_by_display){
|
|
370
|
+
dispatch('getProductsHappyHourTime');
|
|
371
|
+
}
|
|
372
|
+
|
|
362
373
|
return { ...res, data: res.data.data }
|
|
363
374
|
}).catch(
|
|
364
375
|
commonErrorCallback()
|
|
@@ -366,7 +377,7 @@ const actions = {
|
|
|
366
377
|
commit('setFetchingProducts', false);
|
|
367
378
|
});
|
|
368
379
|
},
|
|
369
|
-
getPinnedProducts({ commit, state, rootState }, data) {
|
|
380
|
+
getPinnedProducts({ commit, state, dispatch, rootState }, data) {
|
|
370
381
|
let basketId = undefined;
|
|
371
382
|
try {
|
|
372
383
|
basketId = calculateBasketIdParameter(
|
|
@@ -387,6 +398,8 @@ const actions = {
|
|
|
387
398
|
}
|
|
388
399
|
if (res.data.data.length) {
|
|
389
400
|
res.data.data.forEach(productInCategory => {
|
|
401
|
+
productInCategory.happyHours = [];
|
|
402
|
+
|
|
390
403
|
let quantity = 0;
|
|
391
404
|
state.ShoppingCart
|
|
392
405
|
.filter(itemInCart => Number(itemInCart.RestaurantProductId) === Number(productInCategory.id))
|
|
@@ -398,6 +411,10 @@ const actions = {
|
|
|
398
411
|
commit("setSelectedCategory", null);
|
|
399
412
|
commit("setPinnedProducts", res.data.data);
|
|
400
413
|
commit("setShowPinnedProducts", true);
|
|
414
|
+
|
|
415
|
+
if(rootState.orderiomApiPackage.restaurant.restaurantInfo.ignore_pre_order_timing_by_display){
|
|
416
|
+
dispatch('getProductsHappyHourTime');
|
|
417
|
+
}
|
|
401
418
|
} else {
|
|
402
419
|
commit("setShowPinnedProducts", false);
|
|
403
420
|
}
|
|
@@ -408,6 +425,60 @@ const actions = {
|
|
|
408
425
|
commit('setPinnedProductsFetchedOnce');
|
|
409
426
|
});
|
|
410
427
|
},
|
|
428
|
+
getProductsHappyHourTime({commit, state}){
|
|
429
|
+
if(!state.showPinnedProducts){
|
|
430
|
+
if((!state.products || !state.products.length)) {
|
|
431
|
+
console.error('getProductsHappyHourTime:', 'It is impossible to get products happy hour time before loading the products.');
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
}else{
|
|
435
|
+
if((!state.pinnedProducts || !state.pinnedProducts.length)) {
|
|
436
|
+
console.error('getProductsHappyHourTime:', 'It is impossible to get products happy hour time before loading the products.');
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
if(!state.showPinnedProducts && (!state.selectedCategory || !state.selectedCategory.id)){
|
|
442
|
+
console.error('getProductsHappyHourTime:', 'selected category is unavailable while showPinnedProducts is false too.');
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
commit('setFetchingProductsHappyHour', true);
|
|
446
|
+
return $http.get('api/restaurant/products-happyHour-time', {
|
|
447
|
+
params: {
|
|
448
|
+
[state.showPinnedProducts ? 'pinned' : 'categoryId']:
|
|
449
|
+
state.showPinnedProducts ? true : state.selectedCategory.id
|
|
450
|
+
}
|
|
451
|
+
}).then(res => {
|
|
452
|
+
const data = res.data.data || [];
|
|
453
|
+
if(!Array.isArray(data)) return {...res, data: []};
|
|
454
|
+
|
|
455
|
+
const productList = state.showPinnedProducts ? state.pinnedProducts : state.products;
|
|
456
|
+
if(!productList || !productList.length){
|
|
457
|
+
console.error(`getProductsHappyHourTime: product list is empty`);
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
data.forEach(({happyHour: happyHours, id: productId}) => {
|
|
462
|
+
if(!happyHours?.length) return;
|
|
463
|
+
const product = productList.find(product => product.id === productId);
|
|
464
|
+
if(!product) {
|
|
465
|
+
console.error(`getProductsHappyHourTime: Could not assign happyHours to product:${productId}`);
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
product.happyHours = happyHours.map(happyHourItem => ({
|
|
469
|
+
weekday_id: happyHourItem.weekday_id,
|
|
470
|
+
start_date: happyHourItem.start_date,
|
|
471
|
+
end_date: happyHourItem.end_date,
|
|
472
|
+
}))
|
|
473
|
+
})
|
|
474
|
+
|
|
475
|
+
return {...res, data};
|
|
476
|
+
}).catch(
|
|
477
|
+
commonErrorCallback()
|
|
478
|
+
).finally(() => {
|
|
479
|
+
commit('setFetchingProductsHappyHour', false);
|
|
480
|
+
})
|
|
481
|
+
},
|
|
411
482
|
getBasket({ commit, rootState }, data) {
|
|
412
483
|
if(['string', 'number', 'undefined'].includes(typeof data)) data = {restaurantId: data};
|
|
413
484
|
|