orderiom-api-package 0.4.11 → 0.4.13
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/common.js +16 -1
- package/src/modules/order.js +44 -21
- package/src/modules/product.js +77 -2
package/package.json
CHANGED
package/src/common.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
|
|
3
|
+
export const weekdays = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
|
4
|
+
|
|
3
5
|
export const restaurantIdEnv = process.env.VUE_APP_RESTAURANT_ID
|
|
4
6
|
? parseInt(process.env.VUE_APP_RESTAURANT_ID)
|
|
5
7
|
: window.dynamicData && window.dynamicData.VUE_APP_RESTAURANT_ID
|
|
@@ -37,7 +39,7 @@ export function calculateBasketIdParameter(isLogin, restaurantId) {
|
|
|
37
39
|
console.error(e);
|
|
38
40
|
throw new Error('Basket not found');
|
|
39
41
|
}
|
|
40
|
-
const foundBasket = baskets.
|
|
42
|
+
const foundBasket = baskets.findLast(basket => Number(basket.restaurantId) === (Number(restaurantId) || restaurantIdEnv));
|
|
41
43
|
if(!foundBasket){
|
|
42
44
|
throw new Error('Basket not found');
|
|
43
45
|
}
|
|
@@ -78,6 +80,19 @@ export function updateBasket({commit, basketId, res, restaurantId}){
|
|
|
78
80
|
return true;
|
|
79
81
|
}
|
|
80
82
|
|
|
83
|
+
export function deliveryCodeToName(code) {
|
|
84
|
+
switch (code){
|
|
85
|
+
case 1:
|
|
86
|
+
return 'delivery';
|
|
87
|
+
case 2:
|
|
88
|
+
return 'pickup';
|
|
89
|
+
case 3:
|
|
90
|
+
return 'here';
|
|
91
|
+
default:
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
81
96
|
axios.defaults.baseURL = process.env.VUE_APP_BASE_API_URL || window.dynamicData.VUE_APP_BASE_API_URL;
|
|
82
97
|
axios.interceptors.request.use(config => {
|
|
83
98
|
const token = localStorage.getItem("privateToken") || localStorage.getItem("publicToken");
|
package/src/modules/order.js
CHANGED
|
@@ -593,6 +593,22 @@ const actions = {
|
|
|
593
593
|
// commit('setorder', res.data.data.order)
|
|
594
594
|
// commit('setuserOrder', JSON.parse(res.data.data.order.user_details));
|
|
595
595
|
// commit('setshippigPriceOrder', res.data.data.order.shipping_price);
|
|
596
|
+
const basketData = JSON.parse(localStorage.getItem("basket"));
|
|
597
|
+
if (basketData) {
|
|
598
|
+
const index = basketId
|
|
599
|
+
? basketData.findIndex(item => Number(item.basketId) === Number(basketId))
|
|
600
|
+
: basketData.findIndex(item => Number(item.restaurantId) === Number(data.restaurantId || restaurantIdEnv))
|
|
601
|
+
if (index > -1) {
|
|
602
|
+
basketData.splice(index, 1);
|
|
603
|
+
localStorage.setItem("basket", JSON.stringify(basketData));
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
commit("product/SetSubtotalPrice", "0.00", {root: true});
|
|
608
|
+
commit("product/SetShoppingCart", [], {root: true});
|
|
609
|
+
commit("product/setBasketInfo", {}, {root: true});
|
|
610
|
+
commit("product/setDeliveryTime", "", {root: true});
|
|
611
|
+
commit("product/SetTotalPrice", "0.00", { root: true });
|
|
596
612
|
|
|
597
613
|
if (
|
|
598
614
|
(
|
|
@@ -618,23 +634,6 @@ const actions = {
|
|
|
618
634
|
window.location = res.data.data.paymentLink;
|
|
619
635
|
}
|
|
620
636
|
|
|
621
|
-
const basketData = JSON.parse(localStorage.getItem("basket"));
|
|
622
|
-
if (basketData) {
|
|
623
|
-
const index = basketId
|
|
624
|
-
? basketData.findIndex(item => Number(item.basketId) === Number(basketId))
|
|
625
|
-
: basketData.findIndex(item => Number(item.restaurantId) === Number(data.restaurantId || restaurantIdEnv))
|
|
626
|
-
if (index > -1) {
|
|
627
|
-
basketData.splice(index, 1);
|
|
628
|
-
localStorage.setItem("basket", JSON.stringify(basketData));
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
commit("product/SetSubtotalPrice", "0.00", {root: true});
|
|
633
|
-
commit("product/SetShoppingCart", [], {root: true});
|
|
634
|
-
commit("product/setBasketInfo", {}, {root: true});
|
|
635
|
-
commit("product/setDeliveryTime", "", {root: true});
|
|
636
|
-
commit("product/SetTotalPrice", "0.00", { root: true });
|
|
637
|
-
|
|
638
637
|
return {
|
|
639
638
|
type: "success",
|
|
640
639
|
msg: "ok",
|
|
@@ -817,6 +816,21 @@ const actions = {
|
|
|
817
816
|
})
|
|
818
817
|
.catch(commonErrorCallback());
|
|
819
818
|
},
|
|
819
|
+
formatDate({}, date){
|
|
820
|
+
if(!date) return null;
|
|
821
|
+
return [
|
|
822
|
+
date.getFullYear(),
|
|
823
|
+
(date.getMonth() + 1).toString().padStart(2, '0'),
|
|
824
|
+
(date.getDate()).toString().padStart(2, '0')
|
|
825
|
+
].join('-')
|
|
826
|
+
},
|
|
827
|
+
formatTime({}, date){
|
|
828
|
+
if(!date) return null;
|
|
829
|
+
return [
|
|
830
|
+
date.getHours().toString().padStart(2, '0'),
|
|
831
|
+
date.getMinutes().toString().padStart(2, '0'),
|
|
832
|
+
].join(':')
|
|
833
|
+
},
|
|
820
834
|
addDeliveryTimeToBasket({ dispatch, rootState }, data) {
|
|
821
835
|
let basketId = undefined;
|
|
822
836
|
try {
|
|
@@ -829,18 +843,27 @@ const actions = {
|
|
|
829
843
|
return { type: "error", msg: "Basket not found" };
|
|
830
844
|
}
|
|
831
845
|
|
|
846
|
+
let delivery_time = null;
|
|
847
|
+
if(data.delivery_time instanceof Date){
|
|
848
|
+
delivery_time = [
|
|
849
|
+
dispatch('formatDate', data.delivery_time),
|
|
850
|
+
dispatch('formatTime', data.delivery_time),
|
|
851
|
+
].join(' ')
|
|
852
|
+
}else if(data.date && data.time){
|
|
853
|
+
delivery_time = data.date + ' ' + data.time
|
|
854
|
+
}
|
|
855
|
+
|
|
832
856
|
return $http
|
|
833
857
|
.post("api/basket/add-delivery-time", {
|
|
834
858
|
basketId,
|
|
835
|
-
delivery_time
|
|
836
|
-
data.date && data.time ? data.date + " " + data.time : null,
|
|
859
|
+
delivery_time,
|
|
837
860
|
deliveryType: data.deliveryType,
|
|
838
861
|
duration: data.duration || undefined,
|
|
839
|
-
restaurantId,
|
|
862
|
+
restaurantId: data.restaurantId,
|
|
840
863
|
})
|
|
841
864
|
.then((res) => {
|
|
842
865
|
// console.log(res);
|
|
843
|
-
dispatch("product/getBasket", restaurantId, { root: true });
|
|
866
|
+
dispatch("product/getBasket", data.restaurantId, { root: true });
|
|
844
867
|
return {
|
|
845
868
|
type: "success",
|
|
846
869
|
msg: "ok",
|
package/src/modules/product.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {commonErrorCallback, calculateBasketIdParameter, updateBasket, restaurantIdEnv, $http} from '../common';
|
|
1
|
+
import {commonErrorCallback, calculateBasketIdParameter, updateBasket, deliveryCodeToName, weekdays, restaurantIdEnv, $http} from '../common';
|
|
2
2
|
|
|
3
3
|
const state = () => ({
|
|
4
4
|
selectedTime: null,
|
|
@@ -56,7 +56,52 @@ const getters = {
|
|
|
56
56
|
|
|
57
57
|
return subCategories
|
|
58
58
|
|
|
59
|
-
}
|
|
59
|
+
},
|
|
60
|
+
deliveryType(state){
|
|
61
|
+
return deliveryCodeToName(state.basketInfo.deliveryType);
|
|
62
|
+
},
|
|
63
|
+
deliveryTimes(state, getters){
|
|
64
|
+
if(!getters.deliveryType) return [];
|
|
65
|
+
const property = getters.deliveryType === 'delivery'
|
|
66
|
+
? 'restaurantAvailableTimes'
|
|
67
|
+
: getters.deliveryType === 'here'
|
|
68
|
+
? 'hereTimes'
|
|
69
|
+
: 'restaurantTakeawayTimes';
|
|
70
|
+
return state.restaurantInfo[property] || [];
|
|
71
|
+
},
|
|
72
|
+
disabledDates(state, getters){
|
|
73
|
+
const allowedWeekDays = Array.from(new Set(
|
|
74
|
+
getters.deliveryTimes.map(item => item.weekday)
|
|
75
|
+
)).map(item => weekdays.indexOf(item) + 1)
|
|
76
|
+
|
|
77
|
+
return {weekdays: [1, 2, 3, 4, 5, 6, 7].filter(item => !allowedWeekDays.includes(item))};
|
|
78
|
+
},
|
|
79
|
+
availableTimes(state, getters){
|
|
80
|
+
const result = {};
|
|
81
|
+
getters.deliveryTimes.forEach(range => {
|
|
82
|
+
if(!result[range.weekday]) result[range.weekday] = [];
|
|
83
|
+
const start = range.open_at.slice(0, 5).split(':').map(item => Number(item));
|
|
84
|
+
const end = range.close_at.slice(0, 5).split(':').map(item => Number(item));
|
|
85
|
+
const allowedHours = Array.from({ length: (end[0] + 1) - start[0] }, (_, index) => start[0] + index);
|
|
86
|
+
const allowedMinutes = {};
|
|
87
|
+
|
|
88
|
+
allowedHours.forEach(hour => {
|
|
89
|
+
if(hour < end[0] && hour > start[0]) allowedMinutes[hour] = {start: 0, end: 59};
|
|
90
|
+
else if (hour === start[0] && hour === end[0]) allowedMinutes[hour] = { start: start[1], end: end[1] };
|
|
91
|
+
else if (hour === start[0]) allowedMinutes[hour] = { start: start[1], end: 59 }
|
|
92
|
+
else if(hour === end[0]) allowedMinutes[hour] = { start: 0, end: end[1]}
|
|
93
|
+
else allowedMinutes[hour] = null;
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
result[range.weekday].push({
|
|
97
|
+
start,
|
|
98
|
+
end,
|
|
99
|
+
allowedHours,
|
|
100
|
+
allowedMinutes
|
|
101
|
+
})
|
|
102
|
+
});
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
60
105
|
}
|
|
61
106
|
const mutations = {
|
|
62
107
|
setSelectedDate(state, date) {
|
|
@@ -485,6 +530,36 @@ const actions = {
|
|
|
485
530
|
commonErrorCallback()
|
|
486
531
|
);
|
|
487
532
|
},
|
|
533
|
+
minDateTimeForDelivery ({ state }, deliveryType){
|
|
534
|
+
const dt = deliveryType ? deliveryType : deliveryCodeToName(state.basketInfo.deliveryType)
|
|
535
|
+
if(!dt) return null;
|
|
536
|
+
|
|
537
|
+
const result = new Date();
|
|
538
|
+
const closedToday = state.restaurantInfo ? state.restaurantInfo.closed : false;
|
|
539
|
+
const minHour =
|
|
540
|
+
result.getHours() + Number(state.restaurantInfo[`${dt}_hours`] || 0);
|
|
541
|
+
const isTomorrow = closedToday && minHour < 24;
|
|
542
|
+
result.setHours(
|
|
543
|
+
isTomorrow ? 24 : minHour,
|
|
544
|
+
isTomorrow ? 0 : result.getMinutes(),
|
|
545
|
+
0,
|
|
546
|
+
0
|
|
547
|
+
);
|
|
548
|
+
|
|
549
|
+
return result;
|
|
550
|
+
},
|
|
551
|
+
maxDateTimeForDelivery ({state}, deliveryType){
|
|
552
|
+
const dt = deliveryType ? deliveryType : deliveryCodeToName(state.basketInfo.deliveryType)
|
|
553
|
+
if(!dt) return null;
|
|
554
|
+
|
|
555
|
+
const ad = state.restaurantInfo[`${dt}_available_days`];
|
|
556
|
+
if(!ad) return null;
|
|
557
|
+
|
|
558
|
+
const result = new Date();
|
|
559
|
+
result.setHours(23, 59, 0, 0)
|
|
560
|
+
result.setDate(result.getDate() + Number(ad));
|
|
561
|
+
return result;
|
|
562
|
+
}
|
|
488
563
|
};
|
|
489
564
|
|
|
490
565
|
export default {
|