orderiom-api-package 0.3.41 → 0.3.43

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/modules/order.js +921 -726
@@ -1,763 +1,958 @@
1
- import {commonErrorCallback, calculateBasketIdParameter, restaurantIdEnv, updateBasket, $http} from '../common';
1
+ import {
2
+ commonErrorCallback,
3
+ calculateBasketIdParameter,
4
+ restaurantIdEnv,
5
+ updateBasket,
6
+ $http,
7
+ } from "../common";
2
8
 
3
9
  const state = () => ({
4
- productOrder: null,
5
- userOrder: {},
6
- totalPriceOrder: null,
7
- shippigPriceOrder: null,
8
- order: {},
9
- paymentStatus: null,
10
- shippingPrice: null,
11
- totalPrice: null,
12
- orderList: [],
13
- tableOrder: {}
14
-
10
+ productOrder: null,
11
+ userOrder: {},
12
+ totalPriceOrder: null,
13
+ shippigPriceOrder: null,
14
+ order: {},
15
+ paymentStatus: null,
16
+ shippingPrice: null,
17
+ totalPrice: null,
18
+ orderList: [],
19
+ tableOrder: {},
20
+ externalTableOrders: [],
21
+ tablePaymentStatus: null,
15
22
  });
16
23
  const mutations = {
17
- setproductOrder(state, productOrder) {
18
- state.productOrder = productOrder
19
- },
20
- setuserOrder(state, userOrder) {
21
- state.userOrder = userOrder
22
- },
23
- settotalPriceOrder(state, totalPriceOrder) {
24
- state.totalPriceOrder = totalPriceOrder
25
- },
26
- setshippigPriceOrder(state, shippigPriceOrder) {
27
- state.shippigPriceOrder = shippigPriceOrder
28
- },
29
- setorder(state, order) {
30
- state.order = order
31
- },
32
- setpaymentStatus(state, paymentStatus) {
33
- state.paymentStatus = paymentStatus
34
- },
35
- setshippingPrice(state, shippingPrice) {
36
- state.shippingPrice = shippingPrice;
37
- },
38
- setTotalPrice(state, totalPrice) {
39
- state.totalPrice = totalPrice;
40
- },
41
- setorderList(state, orderList) {
42
- state.orderList = orderList
43
- },
44
- setTableOrder(state, tableOrder) {
45
- state.tableOrder = tableOrder
24
+ setproductOrder(state, productOrder) {
25
+ state.productOrder = productOrder;
26
+ },
27
+ setuserOrder(state, userOrder) {
28
+ state.userOrder = userOrder;
29
+ },
30
+ settotalPriceOrder(state, totalPriceOrder) {
31
+ state.totalPriceOrder = totalPriceOrder;
32
+ },
33
+ setshippigPriceOrder(state, shippigPriceOrder) {
34
+ state.shippigPriceOrder = shippigPriceOrder;
35
+ },
36
+ setorder(state, order) {
37
+ state.order = order;
38
+ },
39
+ setpaymentStatus(state, paymentStatus) {
40
+ state.paymentStatus = paymentStatus;
41
+ },
42
+ setshippingPrice(state, shippingPrice) {
43
+ state.shippingPrice = shippingPrice;
44
+ },
45
+ setTotalPrice(state, totalPrice) {
46
+ state.totalPrice = totalPrice;
47
+ },
48
+ setorderList(state, orderList) {
49
+ state.orderList = orderList;
50
+ },
51
+ setTableOrder(state, tableOrder) {
52
+ state.tableOrder = tableOrder;
53
+ },
54
+ setExternalTableOrders(state, orders) {
55
+ state.externalTableOrders = orders;
56
+ },
57
+ setTablePaymentStatus(state, paymentStatus) {
58
+ state.tablePaymentStatus = paymentStatus;
59
+ },
60
+ };
61
+ const actions = {
62
+ async shoppingCartUpdateCallback({ dispatch, rootState }, data) {
63
+ const getBasketSuccess = await dispatch(
64
+ "product/getBasket",
65
+ data.restaurantId,
66
+ { root: true }
67
+ );
68
+ if (!getBasketSuccess) {
69
+ return {
70
+ type: "error",
71
+ msg: "There was an error in fetching the basket and products",
72
+ };
46
73
  }
47
74
 
48
- }
49
- const actions = {
50
- async shoppingCartUpdateCallback({ dispatch, rootState }, data){
51
- const getBasketSuccess = await dispatch("product/getBasket", data.restaurantId, { root: true });
52
- if(!getBasketSuccess){
53
- return {
54
- type: 'error',
55
- msg: 'There was an error in fetching the basket and products'
56
- }
75
+ return {
76
+ type: "success",
77
+ msg: "",
78
+ };
79
+ },
80
+ createBasket({}, data) {
81
+ var basketData = JSON.parse(localStorage.getItem("basket") || "[]");
82
+ let delivery_time = data.delivery_time
83
+ ? { delivery_time: data.delivery_time }
84
+ : null;
85
+ // Date.prototype.addHours = function (h) {
86
+ // this.setTime(this.getTime() + (h * 60 * 60 * 1000));
87
+ // return this;
88
+ // }
89
+ // var date = new Date().addHours(1);
90
+ // let delivery_time =
91
+ // `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()
92
+ // } ${(date.getHours()).toString().padStart(2, '0')}:${(date.getMinutes()).toString().padStart(2, '0')}`
93
+ return $http
94
+ .post("api/basket/create", {
95
+ ...delivery_time,
96
+ restaurantId: data.restaurantId,
97
+ })
98
+ .then((res) => {
99
+ basketData.push({
100
+ restaurantId: res.data.data.restaurant_id,
101
+ basketId: res.data.data.id,
102
+ });
103
+ localStorage.setItem("basket", JSON.stringify(basketData));
104
+
105
+ // localStorage.setItem("basketId", res.data.id);
106
+ return true;
107
+ })
108
+ .catch(commonErrorCallback());
109
+ },
110
+ createBasketFromOrder({ dispatch }, data) {
111
+ const basketData = JSON.parse(localStorage.getItem("basket") || "[]");
112
+ return $http
113
+ .post("api/order/create-basket", data)
114
+ .then(async (res) => {
115
+ basketData.push({
116
+ restaurantId: data.restaurantId || restaurantIdEnv,
117
+ basketId: res.data.data.basketId,
118
+ });
119
+ localStorage.setItem("basket", JSON.stringify(basketData));
120
+ const result = await dispatch(
121
+ "product/getBasket",
122
+ data.restaurantId || restaurantIdEnv,
123
+ { root: true }
124
+ );
125
+ return {
126
+ type: result ? "success" : "error",
127
+ msg: result
128
+ ? "Basket created"
129
+ : "There was an error in fetching the basket info",
130
+ };
131
+ })
132
+ .catch(commonErrorCallback("There was an error in creating basket"));
133
+ },
134
+ setTable({ rootState }, data) {
135
+ const basket = JSON.parse(localStorage.getItem("basket"));
136
+ const basketId = !rootState.orderiomApiPackage.auth.privateToken
137
+ ? {
138
+ basketId: basket.find(
139
+ (basket) => basket.restaurantId == data.restaurantId
140
+ ).basketId,
57
141
  }
142
+ : {};
143
+ let table = null;
144
+ if (data.tableId) {
145
+ table = { tableId: data.tableId };
146
+ } else if (data.tableName) {
147
+ table = { tableName: data.tableName };
148
+ } else if (data.table) {
149
+ table = { table: data.table };
150
+ }
58
151
 
152
+ return $http
153
+ .post("api/basket/set-table", {
154
+ restaurantId: data.restaurantId,
155
+ ...basketId,
156
+ ...table,
157
+ qrcode: data.qrcode,
158
+ })
159
+ .then((res) => {
59
160
  return {
60
- type: 'success',
61
- msg: ''
161
+ type: "success",
162
+ msg: "ok",
163
+ };
164
+ })
165
+ .catch(commonErrorCallback());
166
+ },
167
+ addToBasket({ dispatch, rootState }, data) {
168
+ // might be null
169
+ const basketProduct =
170
+ rootState.orderiomApiPackage.product.ShoppingCart.find(
171
+ (f) => f.basketProductId === Number(data.productId)
172
+ );
173
+
174
+ const basket = JSON.parse(localStorage.getItem("basket"));
175
+ const basketId = !rootState.orderiomApiPackage.auth.privateToken
176
+ ? {
177
+ basketId: basket.find(
178
+ (basket) => basket.restaurantId == data.restaurantId
179
+ ).basketId,
62
180
  }
63
- },
64
- createBasket({ }, data) {
65
- var basketData = JSON.parse(localStorage.getItem("basket") || "[]");
66
- let delivery_time = data.delivery_time ? { delivery_time: data.delivery_time } : null
67
- // Date.prototype.addHours = function (h) {
68
- // this.setTime(this.getTime() + (h * 60 * 60 * 1000));
69
- // return this;
70
- // }
71
- // var date = new Date().addHours(1);
72
- // let delivery_time =
73
- // `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()
74
- // } ${(date.getHours()).toString().padStart(2, '0')}:${(date.getMinutes()).toString().padStart(2, '0')}`
75
- return $http
76
- .post("api/basket/create", {
77
- ...delivery_time,
78
- restaurantId: data.restaurantId,
79
- })
80
- .then((res) => {
81
- basketData.push({
82
- restaurantId: res.data.data.restaurant_id,
83
- basketId: res.data.data.id,
84
- });
85
- localStorage.setItem("basket", JSON.stringify(basketData));
181
+ : {};
182
+
183
+ if (basketProduct) basketProduct.changingQuantity = true;
184
+
185
+ data.quantity = parseInt(data.quantity);
186
+
187
+ $http
188
+ .post("api/basket/add", {
189
+ ...basketId,
190
+ productId: basketProduct.RestaurantProductId,
191
+ quantity: !data.quantity || data.quantity < 1 ? 1 : data.quantity,
192
+ attributeItems: data.attributeItems.length
193
+ ? data.attributeItems
194
+ : undefined,
195
+ restaurantId: data.restaurantId,
196
+ extraInfo: data.extraInfo,
197
+ })
198
+ .then(async () => {
199
+ return await dispatch("shoppingCartUpdateCallback", {
200
+ restaurantId: data.restaurantId,
201
+ });
202
+ })
203
+ .catch(commonErrorCallback())
204
+ .finally(() => {
205
+ if (basketProduct) basketProduct.changingQuantity = false;
206
+ });
207
+ },
208
+ removeFromBasket({ dispatch, rootState }, data) {
209
+ const basketProduct =
210
+ rootState.orderiomApiPackage.product.ShoppingCart.find(
211
+ (f) => f.basketProductId === Number(data.productId)
212
+ );
213
+
214
+ if (!basketProduct) {
215
+ return {
216
+ type: "error",
217
+ msg: "Product not found",
218
+ };
219
+ }
86
220
 
87
- // localStorage.setItem("basketId", res.data.id);
88
- return true;
89
- })
90
- .catch(
91
- commonErrorCallback()
92
- );
93
- },
94
- createBasketFromOrder({ dispatch }, data) {
95
- const basketData = JSON.parse(localStorage.getItem("basket") || "[]");
96
- return $http
97
- .post("api/order/create-basket", data)
98
- .then(async res => {
99
- basketData.push({
100
- restaurantId: data.restaurantId || restaurantIdEnv,
101
- basketId: res.data.data.basketId,
102
- });
103
- localStorage.setItem("basket", JSON.stringify(basketData));
104
- const result = await dispatch('product/getBasket', data.restaurantId || restaurantIdEnv, { root: true }) ;
105
- return {
106
- type: result ? 'success' : 'error',
107
- msg: result ? 'Basket created' : 'There was an error in fetching the basket info',
108
- }
109
- })
110
- .catch(
111
- commonErrorCallback('There was an error in creating basket')
112
- );
113
- },
114
- setTable({ rootState }, data) {
115
- const basket = JSON.parse(localStorage.getItem("basket"));
116
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
117
- basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
118
- } : {}
119
- let table = null;
120
- if(data.tableId){
121
- table={tableId: data.tableId }
122
- } else if(data.tableName){
123
- table={ tableName: data.tableName }
124
- } else if(data.table){
125
- table = {table : data.table}
221
+ const basket = JSON.parse(localStorage.getItem("basket"));
222
+ const basketId = !rootState.orderiomApiPackage.auth.privateToken
223
+ ? {
224
+ basketId: basket.find(
225
+ (basket) => basket.restaurantId == data.restaurantId
226
+ ).basketId,
126
227
  }
127
-
128
-
129
-
130
- return $http.post('api/basket/set-table', {
131
- restaurantId: data.restaurantId,
132
- ...basketId,
133
- ...table,
134
- qrcode: data.qrcode
135
- }).then((res) => {
136
- return {
137
- type: 'success',
138
- msg: 'ok'
139
- }
140
- }).catch(
141
- commonErrorCallback()
142
- );
143
- },
144
- addToBasket({ dispatch, rootState }, data) {
145
- // might be null
146
- const basketProduct = rootState.orderiomApiPackage.product.ShoppingCart.find(f =>
147
- f.RestaurantProductId === Number(data.productId)
148
- );
149
-
150
- const basket = JSON.parse(localStorage.getItem("basket"));
151
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
152
- basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
153
- } : {}
154
-
155
- if(basketProduct) basketProduct.changingQuantity = true;
156
-
157
- data.quantity = parseInt(data.quantity);
158
-
159
- $http.post("api/basket/add", {
160
- ...basketId,
161
- productId: data.productId,
162
- quantity: !data.quantity || data.quantity < 1 ? 1 : data.quantity,
163
- attributeItems: data.attributeItems.length ? data.attributeItems : undefined,
164
- restaurantId: data.restaurantId,
165
- extraInfo: data.extraInfo
166
- }).then(async () => {
167
- return await dispatch('shoppingCartUpdateCallback', { restaurantId: data.restaurantId });
168
- }).catch(
169
- commonErrorCallback()
170
- ).finally(() => {
171
- if(basketProduct) basketProduct.changingQuantity = false;
228
+ : {};
229
+
230
+ basketProduct.changingQuantity = true;
231
+ $http
232
+ .get("api/basket/remove", {
233
+ params: {
234
+ ...basketId,
235
+ basketProductId: basketProduct.basketProductId,
236
+ restaurantId: data.restaurantId,
237
+ },
238
+ })
239
+ .then(async () => {
240
+ return await dispatch("shoppingCartUpdateCallback", {
241
+ restaurantId: data.restaurantId,
172
242
  });
173
- },
174
- removeFromBasket({ dispatch, rootState }, data) {
175
- const basketProduct = rootState.orderiomApiPackage.product.ShoppingCart.find(f =>
176
- f.RestaurantProductId === Number(data.productId)
177
- );
243
+ })
244
+ .catch(commonErrorCallback())
245
+ .finally(() => {
246
+ basketProduct.changingQuantity = false;
247
+ });
248
+ },
249
+ //TODO: this function is deprecated. use removeFromBasket instead.
250
+ removeFromBasketWithAttr({ dispatch, rootState }, data) {
251
+ const basketProduct =
252
+ rootState.orderiomApiPackage.product.ShoppingCart.find(
253
+ (f) => f.basketProductId === Number(data.basketProductId)
254
+ );
255
+
256
+ if (!basketProduct) {
257
+ return {
258
+ type: "error",
259
+ msg: "Product not found",
260
+ };
261
+ }
178
262
 
179
- if(!basketProduct){
180
- return {
181
- type: 'error',
182
- msg: 'Product not found'
183
- }
263
+ const basket = JSON.parse(localStorage.getItem("basket"));
264
+ const basketId = !rootState.orderiomApiPackage.auth.privateToken
265
+ ? {
266
+ basketId: basket.find(
267
+ (basket) => basket.restaurantId == data.restaurantId
268
+ ).basketId,
184
269
  }
185
-
186
- const basket = JSON.parse(localStorage.getItem("basket"));
187
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
188
- basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
189
- } : {}
190
-
191
- basketProduct.changingQuantity = true;
192
- $http.get("api/basket/remove", {
193
- params: {
194
- ...basketId,
195
- basketProductId: basketProduct.basketProductId,
196
- restaurantId: data.restaurantId,
197
- },
198
- }).then(async () => {
199
- return await dispatch('shoppingCartUpdateCallback', { restaurantId: data.restaurantId });
200
- }).catch(
201
- commonErrorCallback()
202
- ).finally(() => {
203
- basketProduct.changingQuantity = false;
270
+ : {};
271
+
272
+ basketProduct.changingQuantity = true;
273
+ $http
274
+ .get("api/basket/remove", {
275
+ params: {
276
+ ...basketId,
277
+ basketProductId: data.basketProductId,
278
+ restaurantId: data.restaurantId,
279
+ },
280
+ })
281
+ .then(async () => {
282
+ return await dispatch("shoppingCartUpdateCallback", {
283
+ restaurantId: data.restaurantId,
204
284
  });
205
- },
206
- //TODO: this function is deprecated. use removeFromBasket instead.
207
- removeFromBasketWithAttr({ dispatch, rootState }, data) {
208
- const basketProduct = rootState.orderiomApiPackage.product.ShoppingCart.find(f =>
209
- f.basketProductId === Number(data.basketProductId)
210
- );
285
+ })
286
+ .catch(commonErrorCallback())
287
+ .finally(() => {
288
+ basketProduct.changingQuantity = false;
289
+ });
290
+ },
291
+ deleteFromBasket({ dispatch, rootState }, data) {
292
+ const basketProduct =
293
+ rootState.orderiomApiPackage.product.ShoppingCart.find(
294
+ (f) => f.basketProductId === Number(data.productId)
295
+ );
296
+
297
+ if (!basketProduct) {
298
+ return {
299
+ type: "error",
300
+ msg: "Product not found",
301
+ };
302
+ }
211
303
 
212
- if(!basketProduct){
213
- return {
214
- type: 'error',
215
- msg: 'Product not found'
216
- }
304
+ const basket = JSON.parse(localStorage.getItem("basket"));
305
+ const basketId = !rootState.orderiomApiPackage.auth.privateToken
306
+ ? {
307
+ basketId: basket.find(
308
+ (basket) => basket.restaurantId == data.restaurantId
309
+ ).basketId,
217
310
  }
218
-
219
- const basket = JSON.parse(localStorage.getItem("basket"));
220
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
221
- basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
222
- } : {}
223
-
224
- basketProduct.changingQuantity = true;
225
- $http.get("api/basket/remove", {
226
- params: {
227
- ...basketId,
228
- basketProductId: data.basketProductId,
229
- restaurantId: data.restaurantId,
230
- },
231
- }).then(async () => {
232
- return await dispatch('shoppingCartUpdateCallback', { restaurantId: data.restaurantId });
233
- }).catch(
234
- commonErrorCallback()
235
- ).finally(() => {
236
- basketProduct.changingQuantity = false;
311
+ : {};
312
+
313
+ basketProduct.deleting = true;
314
+ return $http
315
+ .get("api/basket/delete-basket-product", {
316
+ params: {
317
+ ...basketId,
318
+ basketProductId: basketProduct.basketProductId,
319
+ restaurantId: data.restaurantId,
320
+ },
321
+ })
322
+ .then(async () => {
323
+ return await dispatch("shoppingCartUpdateCallback", {
324
+ restaurantId: data.restaurantId,
237
325
  });
238
- },
239
- deleteFromBasket({ dispatch, rootState }, data) {
240
- const basketProduct = rootState.orderiomApiPackage.product.ShoppingCart.find(f =>
241
- f.RestaurantProductId === Number(data.productId)
242
- );
326
+ })
327
+ .catch(commonErrorCallback())
328
+ .finally(() => {
329
+ basketProduct.deleting = false;
330
+ });
331
+ },
332
+ //TODO: this function is deprecated. use deleteFromBasket instead.
333
+ deleteFromBasketWithAttr({ dispatch, rootState }, data) {
334
+ const basketProduct =
335
+ rootState.orderiomApiPackage.product.ShoppingCart.find(
336
+ (f) => f.basketProductId === Number(data.basketProductId)
337
+ );
338
+
339
+ if (!basketProduct) {
340
+ return {
341
+ type: "error",
342
+ msg: "Product not found",
343
+ };
344
+ }
243
345
 
244
- if(!basketProduct){
245
- return {
246
- type: 'error',
247
- msg: 'Product not found'
248
- }
346
+ const basket = JSON.parse(localStorage.getItem("basket"));
347
+ const basketId = !rootState.orderiomApiPackage.auth.privateToken
348
+ ? {
349
+ basketId: basket.find(
350
+ (basket) => basket.restaurantId == data.restaurantId
351
+ ).basketId,
249
352
  }
250
-
251
- const basket = JSON.parse(localStorage.getItem("basket"));
252
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
253
- basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
254
- } : {}
255
-
256
- basketProduct.deleting = true;
257
- return $http.get("api/basket/delete-basket-product", {
258
- params: {
259
- ...basketId,
260
- basketProductId: basketProduct.basketProductId,
261
- restaurantId: data.restaurantId,
262
- },
263
- }).then(async () => {
264
- return await dispatch('shoppingCartUpdateCallback', { restaurantId: data.restaurantId });
265
- }).catch(
266
- commonErrorCallback()
267
- ).finally(() => {
268
- basketProduct.deleting = false;
353
+ : {};
354
+
355
+ basketProduct.deleting = true;
356
+ $http
357
+ .get("api/basket/delete-basket-product", {
358
+ params: {
359
+ ...basketId,
360
+ basketProductId: data.basketProductId,
361
+ restaurantId: data.restaurantId,
362
+ },
363
+ })
364
+ .then(async () => {
365
+ return await dispatch("shoppingCartUpdateCallback", {
366
+ restaurantId: data.restaurantId,
269
367
  });
270
- },
271
- //TODO: this function is deprecated. use deleteFromBasket instead.
272
- deleteFromBasketWithAttr({ dispatch, rootState }, data) {
273
- const basketProduct = rootState.orderiomApiPackage.product.ShoppingCart.find(f =>
274
- f.basketProductId === Number(data.basketProductId)
275
- );
276
-
277
- if(!basketProduct){
278
- return {
279
- type: 'error',
280
- msg: 'Product not found'
281
- }
368
+ })
369
+ .catch(commonErrorCallback())
370
+ .finally(() => {
371
+ basketProduct.deleting = false;
372
+ });
373
+ },
374
+ addProductPackageItem({ dispatch, rootState }, data) {
375
+ const basketProduct =
376
+ rootState.orderiomApiPackage.product.ShoppingCart.find(
377
+ (f) => f.basketProductId === Number(data.productId)
378
+ );
379
+
380
+ const basket = JSON.parse(localStorage.getItem("basket"));
381
+ const basketId = !rootState.orderiomApiPackage.auth.privateToken
382
+ ? {
383
+ basketId: basket.find(
384
+ (basket) => basket.restaurantId == data.restaurantId
385
+ ).basketId,
282
386
  }
283
-
284
- const basket = JSON.parse(localStorage.getItem("basket"));
285
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
286
- basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
287
- } : {}
288
-
289
- basketProduct.deleting = true;
290
- $http.get("api/basket/delete-basket-product", {
291
- params: {
292
- ...basketId,
293
- basketProductId: data.basketProductId,
294
- restaurantId: data.restaurantId,
295
- },
296
- }).then(async () => {
297
- return await dispatch('shoppingCartUpdateCallback', { restaurantId: data.restaurantId });
298
- }).catch(
299
- commonErrorCallback()
300
- ).finally(() => {
301
- basketProduct.deleting = false;
387
+ : {};
388
+
389
+ data.quantity = parseInt(data.quantity);
390
+
391
+ if (basketProduct) basketProduct.changingQuantity = true;
392
+ return $http
393
+ .post("api/basket/add-product-package-items", {
394
+ ...basketId,
395
+ ...data,
396
+ productId: basketProduct.RestaurantProductId,
397
+ quantity: !data.quantity || data.quantity < 1 ? 1 : data.quantity,
398
+ })
399
+ .then(async () => {
400
+ return await dispatch("shoppingCartUpdateCallback", {
401
+ restaurantId: data.restaurantId,
302
402
  });
303
- },
304
- addProductPackageItem({ dispatch, rootState }, data) {
305
- const basketProduct = rootState.orderiomApiPackage.product.ShoppingCart.find(f =>
306
- f.RestaurantProductId === Number(data.productId)
307
- );
308
-
309
- const basket = JSON.parse(localStorage.getItem("basket"));
310
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
311
- basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
312
- } : {}
313
-
314
- data.quantity = parseInt(data.quantity);
403
+ })
404
+ .catch(commonErrorCallback())
405
+ .finally(() => {
406
+ if (basketProduct) basketProduct.changingQuantity = false;
407
+ });
408
+ },
409
+ addAddress({ rootState }, data) {
410
+ const basket = JSON.parse(localStorage.getItem("basket"));
411
+ const basketId = !rootState.orderiomApiPackage.auth.privateToken
412
+ ? {
413
+ basketId: basket.find(
414
+ (basket) => basket.restaurantId == data.restaurantId
415
+ ).basketId,
416
+ }
417
+ : {};
418
+ return $http
419
+ .post("api/basket/add-address", {
420
+ ...basketId,
421
+ restaurantId: data.restaurantId,
422
+ userInfo: data.userInfo,
423
+ })
424
+ .then(() => {
425
+ return true;
426
+ })
427
+ .catch(commonErrorCallback());
428
+ },
429
+ checkAddress({ rootState }, data) {
430
+ const basket = JSON.parse(localStorage.getItem("basket"));
431
+ const basketId = !rootState.orderiomApiPackage.auth.privateToken
432
+ ? {
433
+ basketId: basket.find(
434
+ (basket) => basket.restaurantId == data.restaurantId
435
+ ).basketId,
436
+ }
437
+ : {};
438
+ return $http
439
+ .get("api/order/check-address", {
440
+ params: {
441
+ ...basketId,
442
+ restaurantId: data.restaurantId,
443
+ postalCode: data.postalCode,
444
+ deliveryType: data.deliveryType,
445
+ date: rootState.orderiomApiPackage.product.deliveryTime,
446
+ },
447
+ })
448
+ .then((res) => {
449
+ return {
450
+ type: "success",
451
+ msg: "ok",
452
+ };
453
+ })
454
+ .catch(commonErrorCallback());
455
+ },
456
+ removeElement({}, data) {
457
+ var index = data.array.indexOf(data.item);
458
+ if (index > -1) {
459
+ data.array.splice(index, 1);
460
+ }
461
+ },
462
+ createOrder({ commit, rootState }, data) {
463
+ const basketData = JSON.parse(localStorage.getItem("basket"));
464
+ const basketId = !rootState.orderiomApiPackage.auth.privateToken
465
+ ? {
466
+ basketId: data.basketId,
467
+ }
468
+ : {};
469
+ const restaurantID = data.restaurantId
470
+ ? { restaurantId: data.restaurantId }
471
+ : {};
472
+ return $http
473
+ .post("api/order/create-order", {
474
+ ...basketId,
475
+ ...restaurantID,
476
+ paymentType: data.paymentType,
477
+ ...(data.paymentType === "payFix" && {
478
+ qrCode: data.payfix_qrcode,
479
+ pin: data.payfix_pin,
480
+ }),
481
+ })
482
+ .then((res) => {
483
+ // localStorage.setItem("orderId", res.data.data.order.id);
484
+ // commit('setproductOrder', res.data.data.product)
485
+ // commit('settotalPriceOrder', res.data.data.order.total_price)
486
+ // commit('setorder', res.data.data.order)
487
+ // commit('setuserOrder', JSON.parse(res.data.data.order.user_details));
488
+ // commit('setshippigPriceOrder', res.data.data.order.shipping_price);
489
+
490
+ if (
491
+ (res.data.data.paymentLink.includes("/paymentstatus/?") ||
492
+ res.data.data.paymentLink.includes("/paymentstatus?")) &&
493
+ data.$router &&
494
+ data.routeName
495
+ ) {
496
+ data.$router.push({
497
+ name: data.routeName,
498
+ query: res.data.data.paymentLink
499
+ .split("?")[1]
500
+ .split("&")
501
+ .map((query) => query.split("="))
502
+ .reduce((result, element) => {
503
+ if (!element) return result;
504
+ result[element[0]] = element[1];
505
+ return result;
506
+ }, {}),
507
+ });
508
+ } else {
509
+ window.location = res.data.data.paymentLink;
510
+ }
315
511
 
316
- if(basketProduct) basketProduct.changingQuantity = true;
317
- return $http.post('api/basket/add-product-package-items', {
318
- ...basketId,
319
- ...data,
320
- quantity: !data.quantity || data.quantity < 1 ? 1 : data.quantity,
321
- }).then(async () => {
322
- return await dispatch('shoppingCartUpdateCallback', { restaurantId: data.restaurantId });
323
- }).catch(
324
- commonErrorCallback()
325
- ).finally(() => {
326
- if(basketProduct) basketProduct.changingQuantity = false;
327
- });
328
- },
329
- addAddress({ rootState }, data) {
330
- const basket = JSON.parse(localStorage.getItem("basket"));
331
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
332
- basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
333
- } : {}
334
- return $http
335
- .post("api/basket/add-address", {
336
- ...basketId,
337
- restaurantId: data.restaurantId,
338
- userInfo: data.userInfo,
339
- })
340
- .then(() => {
341
- return true;
342
- })
343
- .catch(
344
- commonErrorCallback()
512
+ var index = data.basket
513
+ ? basketData.indexOf(
514
+ basketData.find((item) => item.basketId == data.basket)
515
+ )
516
+ : basketData.indexOf(
517
+ basketData.find((item) => item.restaurantId == data.restaurantId)
345
518
  );
346
- },
347
- checkAddress({ rootState }, data) {
348
- const basket = JSON.parse(localStorage.getItem("basket"));
349
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
350
- basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
351
- } : {}
352
- return $http
353
- .get("api/order/check-address", {
354
- params: {
355
- ...basketId,
356
- restaurantId: data.restaurantId,
357
- postalCode: data.postalCode,
358
- deliveryType: data.deliveryType,
359
- date: rootState.orderiomApiPackage.product.deliveryTime,
360
- },
361
- })
362
- .then((res) => {
363
- return {
364
- type: 'success',
365
- msg: 'ok'
366
- }
367
- })
368
- .catch(
369
- commonErrorCallback()
370
- );
371
- },
372
- removeElement({ }, data) {
373
- var index = data.array.indexOf(data.item);
374
519
  if (index > -1) {
375
- data.array.splice(index, 1);
520
+ basketData.splice(index, 1);
376
521
  }
377
- },
378
- createOrder({ commit, rootState }, data) {
379
- const basketData = JSON.parse(localStorage.getItem("basket"));
380
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
381
- basketId: data.basketId
382
- } : {}
383
- const restaurantID = data.restaurantId ? { restaurantId: data.restaurantId } : {}
384
- return $http
385
- .post("api/order/create-order", {
386
- ...basketId,
387
- ...restaurantID,
388
- paymentType: data.paymentType,
389
- ...(data.paymentType === 'payFix' && {
390
- qrCode: data.payfix_qrcode,
391
- pin: data.payfix_pin
392
- }),
393
- })
394
- .then((res) => {
395
- // localStorage.setItem("orderId", res.data.data.order.id);
396
- // commit('setproductOrder', res.data.data.product)
397
- // commit('settotalPriceOrder', res.data.data.order.total_price)
398
- // commit('setorder', res.data.data.order)
399
- // commit('setuserOrder', JSON.parse(res.data.data.order.user_details));
400
- // commit('setshippigPriceOrder', res.data.data.order.shipping_price);
401
-
402
- if(
403
- (
404
- res.data.data.paymentLink.includes("/paymentstatus/?") ||
405
- res.data.data.paymentLink.includes("/paymentstatus?")
406
- ) &&
407
- data.$router &&
408
- data.routeName
409
- ){
410
- data.$router.push({
411
- name: data.routeName,
412
- query: res.data.data.paymentLink
413
- .split('?')[1]
414
- .split('&')
415
- .map(query => query.split('='))
416
- .reduce((result, element) => {
417
- if(!element) return result;
418
- result[element[0]] = element[1];
419
- return result;
420
- }, {})
421
- });
422
- } else {
423
- window.location = res.data.data.paymentLink;
424
- }
425
-
426
- var index = data.basket ? basketData.indexOf(basketData.find((item) => item.basketId == data.basket)) :
427
- basketData.indexOf(basketData.find((item) => item.restaurantId == data.restaurantId));
428
- if (index > -1) {
429
- basketData.splice(index, 1);
430
- }
431
- localStorage.setItem("basket", JSON.stringify(basketData));
432
- // console.log(basketData);
433
- commit("product/SetSubtotalPrice", "0.00", { root: true });
434
- commit("product/SetShoppingCart", [], { root: true });
435
- commit("product/setBasketInfo", {}, { root: true });
436
- commit("product/setDeliveryTime", "", { root: true });
437
- commit("product/SetTotalPrice", "0.00", { root: true });
438
- return {
439
- type: 'success',
440
- msg: 'ok'
441
- }
442
- })
443
- .catch(
444
- commonErrorCallback()
445
- );
446
- },
447
- getOrder({ commit }, orderId) {
448
- return $http
449
- .get("api/order", {
450
- params: {
451
- orderId: orderId
452
- },
453
- })
454
- .then((res) => {
455
- commit('setproductOrder', res.data.data.products)
456
- commit('settotalPriceOrder', res.data.data.order.total_price)
457
- commit('setorder', res.data.data.order)
458
- commit('setTableOrder', res.data.data.table)
459
- commit('setuserOrder', JSON.parse(res.data.data.order.user_details));
460
- commit('setshippigPriceOrder', res.data.data.order.shipping_price)
461
- commit("product/SetSubtotalPrice", "0.00", { root: true });
462
- commit("product/SetShoppingCart", [], { root: true });
463
- commit("product/setDeliveryTime", "", { root: true });
464
- commit("product/SetTotalPrice", "0.00", { root: true });
465
- return {
466
- type: 'success',
467
- msg: "ok"
468
- }
469
- })
470
- .catch(
471
- commonErrorCallback()
472
- );
473
- },
474
- requestBill({ }, orderId) {
475
- return $http
476
- .get("api/order/bill-request", {
477
- params: {
478
- order_id: orderId
479
- },
480
- })
481
- .then((res) => {
482
- return {
483
- type: 'success',
484
- msg: res.data.message.body
485
- }
486
- })
487
- .catch(
488
- commonErrorCallback()
489
- );
490
-
491
- },
492
- preparePayment({ rootState }, data) {
493
- const basket = JSON.parse(localStorage.getItem("basket"));
494
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
495
- basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
496
- } : {}
497
- const restaurantID = data.restaurantId ? { restaurantId: data.restaurantId } : {}
498
-
499
- $http.get('api/payment/prepare', {
500
- params: {
501
- ...basketId,
502
- ...restaurantID,
503
- }
504
- }).then((result) => {
505
- window.location = result.data.data.mollieLink;
506
- }).catch(
507
- commonErrorCallback()
522
+ localStorage.setItem("basket", JSON.stringify(basketData));
523
+ // console.log(basketData);
524
+ commit("product/SetSubtotalPrice", "0.00", { root: true });
525
+ commit("product/SetShoppingCart", [], { root: true });
526
+ commit("product/setBasketInfo", {}, { root: true });
527
+ commit("product/setDeliveryTime", "", { root: true });
528
+ commit("product/SetTotalPrice", "0.00", { root: true });
529
+ return {
530
+ type: "success",
531
+ msg: "ok",
532
+ };
533
+ })
534
+ .catch(commonErrorCallback());
535
+ },
536
+ getOrder({ commit }, orderId) {
537
+ return $http
538
+ .get("api/order", {
539
+ params: {
540
+ orderId: orderId,
541
+ },
542
+ })
543
+ .then((res) => {
544
+ commit("setproductOrder", res.data.data.products);
545
+ commit("settotalPriceOrder", res.data.data.order.total_price);
546
+ commit("setorder", res.data.data.order);
547
+ commit("setTableOrder", res.data.data.table);
548
+ commit("setuserOrder", JSON.parse(res.data.data.order.user_details));
549
+ commit("setshippigPriceOrder", res.data.data.order.shipping_price);
550
+ commit("product/SetSubtotalPrice", "0.00", { root: true });
551
+ commit("product/SetShoppingCart", [], { root: true });
552
+ commit("product/setDeliveryTime", "", { root: true });
553
+ commit("product/SetTotalPrice", "0.00", { root: true });
554
+ return {
555
+ type: "success",
556
+ msg: "ok",
557
+ };
558
+ })
559
+ .catch(commonErrorCallback());
560
+ },
561
+ requestBill({}, orderId) {
562
+ return $http
563
+ .get("api/order/bill-request", {
564
+ params: {
565
+ order_id: orderId,
566
+ },
567
+ })
568
+ .then((res) => {
569
+ return {
570
+ type: "success",
571
+ msg: res.data.message.body,
572
+ };
573
+ })
574
+ .catch(commonErrorCallback());
575
+ },
576
+ preparePayment({ rootState }, data) {
577
+ const basket = JSON.parse(localStorage.getItem("basket"));
578
+ const basketId = !rootState.orderiomApiPackage.auth.privateToken
579
+ ? {
580
+ basketId: basket.find(
581
+ (basket) => basket.restaurantId == data.restaurantId
582
+ ).basketId,
583
+ }
584
+ : {};
585
+ const restaurantID = data.restaurantId
586
+ ? { restaurantId: data.restaurantId }
587
+ : {};
588
+
589
+ $http
590
+ .get("api/payment/prepare", {
591
+ params: {
592
+ ...basketId,
593
+ ...restaurantID,
594
+ },
595
+ })
596
+ .then((result) => {
597
+ window.location = result.data.data.mollieLink;
598
+ })
599
+ .catch(commonErrorCallback());
600
+ },
601
+ updatePaymentStatus({ dispatch, commit }, data) {
602
+ return $http
603
+ .get(`api/payment/update`, {
604
+ params: { paymentId: data.paymentId, status: data.status },
605
+ })
606
+ .then((res) => {
607
+ const status = res.data.data.status;
608
+ commit("setpaymentStatus", status);
609
+ // if (status == "paid") {
610
+ // dispatch('createOrder', data.basketId)
611
+ return {
612
+ type: "success",
613
+ msg: "ok",
614
+ };
615
+ // }
616
+ // return {
617
+ // type: 'error',
618
+ // msg: 'ok'
619
+ // }
620
+ })
621
+ .catch(commonErrorCallback());
622
+ },
623
+ getShippingPrice({ commit, rootState }, data) {
624
+ let basketId = undefined;
625
+ try {
626
+ basketId = calculateBasketIdParameter(
627
+ !!rootState.orderiomApiPackage.auth.privateToken,
628
+ data.restaurantId
629
+ );
630
+ } catch (e) {
631
+ console.error(e);
632
+ return { type: "error", msg: "Basket not found" };
633
+ }
634
+ if (!data.postalCode || !data.deliveryType) {
635
+ return;
636
+ }
637
+ return $http
638
+ .get(`api/restaurant/shipping-price`, {
639
+ params: {
640
+ deliveryType: data.deliveryType,
641
+ postalCode: data.postalCode,
642
+ restaurantId: data.restaurantId,
643
+ basketId: basketId,
644
+ },
645
+ })
646
+ .then((res) => {
647
+ commit("setshippingPrice", res.data.data.shippingPrice.toString());
648
+ commit(
649
+ "product/setshippingPrice",
650
+ res.data.data.shippingPrice.toString(),
651
+ { root: true }
508
652
  );
509
- },
510
- updatePaymentStatus({ dispatch, commit }, data) {
511
- return $http
512
- .get(`api/payment/update`, { params: { paymentId: data.paymentId ,status:data.status} })
513
- .then((res) => {
514
- const status = res.data.data.status;
515
- commit('setpaymentStatus', status)
516
- // if (status == "paid") {
517
- // dispatch('createOrder', data.basketId)
518
- return {
519
- type: 'success',
520
- msg: 'ok'
521
- }
522
- // }
523
- // return {
524
- // type: 'error',
525
- // msg: 'ok'
526
- // }
527
- })
528
- .catch(
529
- commonErrorCallback()
530
- );
531
- },
532
- getShippingPrice({ commit, rootState }, data) {
533
- let basketId = undefined;
534
- try{
535
- basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken, data.restaurantId);
536
- } catch(e) {
537
- console.error(e);
538
- return { type: 'error', msg: 'Basket not found' }
653
+ if (res.data.data.totalPrice) {
654
+ const value = Number(res.data.data.totalPrice).toFixed(2);
655
+ commit("setTotalPrice", value);
656
+ commit("product/SetTotalPrice", value, { root: true });
539
657
  }
540
- if (!data.postalCode || !data.deliveryType) {
541
- return
658
+ if (res.data.data.totalWithDiscount) {
659
+ const value = Number(res.data.data.totalWithDiscount).toFixed(2);
660
+ commit("product/setTotalWithDiscount", value, { root: true });
542
661
  }
543
- return $http
544
- .get(`api/restaurant/shipping-price`, {
545
- params: {
546
- deliveryType: data.deliveryType,
547
- postalCode: data.postalCode,
548
- restaurantId: data.restaurantId,
549
- basketId:basketId
550
- },
551
- })
552
- .then((res) => {
553
- commit('setshippingPrice', res.data.data.shippingPrice.toString());
554
- commit('product/setshippingPrice', res.data.data.shippingPrice.toString(),{root: true});
555
- if(res.data.data.totalPrice){
556
- const value = Number(res.data.data.totalPrice).toFixed(2);
557
- commit('setTotalPrice', value);
558
- commit('product/SetTotalPrice', value, {root: true});
559
- }
560
- if(res.data.data.totalWithDiscount){
561
- const value = Number(res.data.data.totalWithDiscount).toFixed(2);
562
- commit('product/setTotalWithDiscount', value, {root: true});
563
- }
564
662
 
565
- return {
566
- type: 'success',
567
- msg: ''
568
- }
569
- })
570
- .catch(
571
- commonErrorCallback()
572
- );
573
- },
574
- getTotalPrice({ commit, rootState }, data) {
575
- const basket = JSON.parse(localStorage.getItem("basket"));
576
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
577
- basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
578
- } : {}
579
- if (!data.postalCode || !data.deliveryType) {
580
- return
663
+ return {
664
+ type: "success",
665
+ msg: "",
666
+ };
667
+ })
668
+ .catch(commonErrorCallback());
669
+ },
670
+ getTotalPrice({ commit, rootState }, data) {
671
+ const basket = JSON.parse(localStorage.getItem("basket"));
672
+ const basketId = !rootState.orderiomApiPackage.auth.privateToken
673
+ ? {
674
+ basketId: basket.find(
675
+ (basket) => basket.restaurantId == data.restaurantId
676
+ ).basketId,
581
677
  }
582
- return $http
583
- .get(`api/basket/total-price`, {
584
- params: {
585
- ...basketId,
586
- deliveryType: data.deliveryType,
587
- postalCode: data.postalCode,
588
- restaurantId: data.restaurantId,
589
- },
590
- })
591
- .then((res) => {
592
- commit('setTotalPrice', res.data.data.totalPrice)
593
- return {
594
- type: 'success',
595
- msg: 'ok'
596
- }
597
- })
598
- .catch(
599
- commonErrorCallback()
600
- );
601
- },
602
- addDeliveryTimeToBasket({ dispatch, rootState }, data) {
603
- const basket = JSON.parse(localStorage.getItem("basket"));
604
- const restaurantId = parseInt(data.restaurantId ? data.restaurantId : restaurantIdEnv)
605
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
606
- basketId: basket.find(basket =>
607
- parseInt(basket.restaurantId) === parseInt(restaurantId)
608
- ).basketId
609
- } : {}
610
- return $http
611
- .post("api/basket/add-delivery-time", {
612
- ...basketId,
613
- delivery_time: data.date && data.time ? data.date + " " + data.time : null,
614
- deliveryType: data.deliveryType,
615
- duration: data.duration || undefined,
616
- restaurantId
617
- })
618
- .then((res) => {
619
- // console.log(res);
620
- dispatch('product/getBasket', restaurantId, { root: true })
621
- return {
622
- type: 'success',
623
- msg: 'ok'
624
- }
625
- })
626
- .catch(
627
- commonErrorCallback()
628
- );
629
- },
630
- getOrderHistory({ commit }, data) {
631
- return $http
632
- .get("api/order/history", { params: data })
633
- .then((res) => {
634
- commit('setorderList', res.data.data)
635
- })
636
- .catch(
637
- commonErrorCallback()
638
- );
639
- },
640
- addVoucher({ rootState, dispatch }, data) {
641
- const basket = JSON.parse(localStorage.getItem("basket"));
642
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
643
- basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
644
- } : {}
645
- return $http.post('api/basket/add-voucher-to-basket', null, {
646
- params: {
647
- voucherCode: data.voucherCode,
648
- restaurantId: data.restaurantId,
649
- ...basketId
650
- }
651
- }).then((result) => {
652
- dispatch('product/getBasket', data.restaurantId, { root: true })
653
- return {
654
- type: 'success',
655
- msg: result.message
656
- }
657
- }).catch(
658
- commonErrorCallback()
659
- );
660
- },
661
- removeVoucher({ rootState, dispatch }, restaurantId) {
662
- const basket = JSON.parse(localStorage.getItem("basket"));
663
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
664
- basketId: basket.find((basket) => basket.restaurantId == restaurantId).basketId
665
- } : {}
666
- return $http.get('api/basket/remove-voucher-from-basket', {
667
- params: {
668
- ...basketId,
669
- restaurantId: restaurantId
670
- }
671
- }).then((result) => {
672
- dispatch('product/getBasket', restaurantId, { root: true })
673
- return {
674
- type: 'success',
675
- msg: 'removed'
676
- }
677
- }).catch(
678
- commonErrorCallback()
679
- );
680
- },
681
- addTip({ rootState, dispatch }, data) {
682
- const basket = JSON.parse(localStorage.getItem("basket"));
683
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
684
- basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
685
- } : {}
686
- return $http.post('api/basket/add-tip', {
687
- ...basketId,
688
- restaurantId: data.restaurantId,
689
- tip_price: data.tip_price
690
- }).then((result) => {
691
- dispatch('product/getBasket', data.restaurantId, { root: true })
692
- return {
693
- type: 'success',
694
- msg: 'removed'
695
- }
696
- }).catch(
697
- commonErrorCallback()
698
- );
699
- },
700
- removeTip({ rootState, dispatch }, restaurantId) {
701
- const basket = JSON.parse(localStorage.getItem("basket"));
702
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
703
- basketId: basket.find((basket) => basket.restaurantId == restaurantId).basketId
704
- } : {}
705
- return $http.put('api/basket/remove-tip-from-basket', {
706
- ...basketId,
707
- restaurantId: restaurantId,
708
- }).then((result) => {
709
- dispatch('product/getBasket', restaurantId, { root: true })
710
- return {
711
- type: 'success',
712
- msg: 'removed'
713
- }
714
- }).catch(
715
- commonErrorCallback()
716
- );
717
- },
718
- checkOrderValidity({ rootState }, data) {
719
- const basket = JSON.parse(localStorage.getItem("basket"));
720
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
721
- basketId: basket.find((basket) => basket.restaurantId == data.restaurantId).basketId
722
- } : {}
723
- return $http.post('api/order/is-valid', null, {
724
- params: {
725
- restaurantId: data.restaurantId,
726
- ...basketId
727
- }
728
- }).then((result) => {
729
- return {
730
- type: 'success',
731
- msg: 'ok'
732
- }
733
- }).catch(
734
- commonErrorCallback()
735
- );
736
- },
737
- editCartProductExtraInfo({rootState, commit}, data){
738
- let basketId = undefined;
739
- try{
740
- basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken, data.restaurantId);
741
- } catch(e) {
742
- console.error(e);
743
- return {type: 'error', msg: 'Basket not found'};
678
+ : {};
679
+ if (!data.postalCode || !data.deliveryType) {
680
+ return;
681
+ }
682
+ return $http
683
+ .get(`api/basket/total-price`, {
684
+ params: {
685
+ ...basketId,
686
+ deliveryType: data.deliveryType,
687
+ postalCode: data.postalCode,
688
+ restaurantId: data.restaurantId,
689
+ },
690
+ })
691
+ .then((res) => {
692
+ commit("setTotalPrice", res.data.data.totalPrice);
693
+ return {
694
+ type: "success",
695
+ msg: "ok",
696
+ };
697
+ })
698
+ .catch(commonErrorCallback());
699
+ },
700
+ addDeliveryTimeToBasket({ dispatch, rootState }, data) {
701
+ const basket = JSON.parse(localStorage.getItem("basket"));
702
+ const restaurantId = parseInt(
703
+ data.restaurantId ? data.restaurantId : restaurantIdEnv
704
+ );
705
+ const basketId = !rootState.orderiomApiPackage.auth.privateToken
706
+ ? {
707
+ basketId: basket.find(
708
+ (basket) => parseInt(basket.restaurantId) === parseInt(restaurantId)
709
+ ).basketId,
744
710
  }
745
-
746
- return $http.post('api/basket/update-extraInfo', {
747
- basketId,
748
- restaurantId: data.restaurantId || restaurantIdEnv,
749
- ...data
750
- }).then(res =>
751
- updateBasket({commit, basketId, res, restaurantId: data ? data.restaurantId : undefined})
752
- ).catch(err => {
753
- console.error(err);
754
- return false;
755
- });
711
+ : {};
712
+ return $http
713
+ .post("api/basket/add-delivery-time", {
714
+ ...basketId,
715
+ delivery_time:
716
+ data.date && data.time ? data.date + " " + data.time : null,
717
+ deliveryType: data.deliveryType,
718
+ duration: data.duration || undefined,
719
+ restaurantId,
720
+ })
721
+ .then((res) => {
722
+ // console.log(res);
723
+ dispatch("product/getBasket", restaurantId, { root: true });
724
+ return {
725
+ type: "success",
726
+ msg: "ok",
727
+ };
728
+ })
729
+ .catch(commonErrorCallback());
730
+ },
731
+ getOrderHistory({ commit }, data) {
732
+ return $http
733
+ .get("api/order/history", { params: data })
734
+ .then((res) => {
735
+ commit("setorderList", res.data.data);
736
+ })
737
+ .catch(commonErrorCallback());
738
+ },
739
+ addVoucher({ rootState, dispatch }, data) {
740
+ const basket = JSON.parse(localStorage.getItem("basket"));
741
+ const basketId = !rootState.orderiomApiPackage.auth.privateToken
742
+ ? {
743
+ basketId: basket.find(
744
+ (basket) => basket.restaurantId == data.restaurantId
745
+ ).basketId,
746
+ }
747
+ : {};
748
+ return $http
749
+ .post("api/basket/add-voucher-to-basket", null, {
750
+ params: {
751
+ voucherCode: data.voucherCode,
752
+ restaurantId: data.restaurantId,
753
+ ...basketId,
754
+ },
755
+ })
756
+ .then((result) => {
757
+ dispatch("product/getBasket", data.restaurantId, { root: true });
758
+ return {
759
+ type: "success",
760
+ msg: result.message,
761
+ };
762
+ })
763
+ .catch(commonErrorCallback());
764
+ },
765
+ removeVoucher({ rootState, dispatch }, restaurantId) {
766
+ const basket = JSON.parse(localStorage.getItem("basket"));
767
+ const basketId = !rootState.orderiomApiPackage.auth.privateToken
768
+ ? {
769
+ basketId: basket.find((basket) => basket.restaurantId == restaurantId)
770
+ .basketId,
771
+ }
772
+ : {};
773
+ return $http
774
+ .get("api/basket/remove-voucher-from-basket", {
775
+ params: {
776
+ ...basketId,
777
+ restaurantId: restaurantId,
778
+ },
779
+ })
780
+ .then((result) => {
781
+ dispatch("product/getBasket", restaurantId, { root: true });
782
+ return {
783
+ type: "success",
784
+ msg: "removed",
785
+ };
786
+ })
787
+ .catch(commonErrorCallback());
788
+ },
789
+ addTip({ rootState, dispatch }, data) {
790
+ const basket = JSON.parse(localStorage.getItem("basket"));
791
+ const basketId = !rootState.orderiomApiPackage.auth.privateToken
792
+ ? {
793
+ basketId: basket.find(
794
+ (basket) => basket.restaurantId == data.restaurantId
795
+ ).basketId,
796
+ }
797
+ : {};
798
+ return $http
799
+ .post("api/basket/add-tip", {
800
+ ...basketId,
801
+ restaurantId: data.restaurantId,
802
+ tip_price: data.tip_price,
803
+ })
804
+ .then((result) => {
805
+ dispatch("product/getBasket", data.restaurantId, { root: true });
806
+ return {
807
+ type: "success",
808
+ msg: "removed",
809
+ };
810
+ })
811
+ .catch(commonErrorCallback());
812
+ },
813
+ removeTip({ rootState, dispatch }, restaurantId) {
814
+ const basket = JSON.parse(localStorage.getItem("basket"));
815
+ const basketId = !rootState.orderiomApiPackage.auth.privateToken
816
+ ? {
817
+ basketId: basket.find((basket) => basket.restaurantId == restaurantId)
818
+ .basketId,
819
+ }
820
+ : {};
821
+ return $http
822
+ .put("api/basket/remove-tip-from-basket", {
823
+ ...basketId,
824
+ restaurantId: restaurantId,
825
+ })
826
+ .then((result) => {
827
+ dispatch("product/getBasket", restaurantId, { root: true });
828
+ return {
829
+ type: "success",
830
+ msg: "removed",
831
+ };
832
+ })
833
+ .catch(commonErrorCallback());
834
+ },
835
+ checkOrderValidity({ rootState }, data) {
836
+ const basket = JSON.parse(localStorage.getItem("basket"));
837
+ const basketId = !rootState.orderiomApiPackage.auth.privateToken
838
+ ? {
839
+ basketId: basket.find(
840
+ (basket) => basket.restaurantId == data.restaurantId
841
+ ).basketId,
842
+ }
843
+ : {};
844
+ return $http
845
+ .post("api/order/is-valid", null, {
846
+ params: {
847
+ restaurantId: data.restaurantId,
848
+ ...basketId,
849
+ },
850
+ })
851
+ .then((result) => {
852
+ return {
853
+ type: "success",
854
+ msg: "ok",
855
+ };
856
+ })
857
+ .catch(commonErrorCallback());
858
+ },
859
+ editCartProductExtraInfo({ rootState, commit }, data) {
860
+ let basketId = undefined;
861
+ try {
862
+ basketId = calculateBasketIdParameter(
863
+ !!rootState.orderiomApiPackage.auth.privateToken,
864
+ data.restaurantId
865
+ );
866
+ } catch (e) {
867
+ console.error(e);
868
+ return { type: "error", msg: "Basket not found" };
756
869
  }
757
- }
870
+
871
+ return $http
872
+ .post("api/basket/update-extraInfo", {
873
+ basketId,
874
+ restaurantId: data.restaurantId || restaurantIdEnv,
875
+ ...data,
876
+ })
877
+ .then((res) =>
878
+ updateBasket({
879
+ commit,
880
+ basketId,
881
+ res,
882
+ restaurantId: data ? data.restaurantId : undefined,
883
+ })
884
+ )
885
+ .catch((err) => {
886
+ console.error(err);
887
+ return false;
888
+ });
889
+ },
890
+ getTableExternalOrder({ commit }, { restaurantId, tableName }) {
891
+ console.log("getTableExternalOrder");
892
+ $http
893
+ .post("api/table-payments/create", {
894
+ restaurantId,
895
+ tableName,
896
+ })
897
+ .then((res) => {
898
+ commit("setExternalTableOrders", res.data.data);
899
+ })
900
+ .catch(commonErrorCallback());
901
+ },
902
+ payTableExternalOrder(
903
+ { rootState },
904
+ { tablePaymentId, paymentType, qrcode = null, pin = null }
905
+ ) {
906
+ $http
907
+ .post("/api/table-payments/pay", {
908
+ tablePaymentId,
909
+ paymentType,
910
+ ...(paymentType === "payFix" && {
911
+ qrCode: qrcode,
912
+ pin: pin,
913
+ }),
914
+ })
915
+ .then((res) => {
916
+ console.log(res);
917
+ window.location = res.data.data.paymentLink;
918
+ return {
919
+ type: "success",
920
+ msg: "ok",
921
+ };
922
+ })
923
+ .catch(commonErrorCallback());
924
+ },
925
+ updateTablePaymentStatus({ commit }, data) {
926
+ return $http
927
+ .get(`/api/table-payments/update`, {
928
+ params: { paymentId: data.paymentId, status: data.status },
929
+ })
930
+ .then((res) => {
931
+ const status = res.data.data.status;
932
+ commit("setTablePaymentStatus", status);
933
+ return {
934
+ type: "success",
935
+ msg: "ok",
936
+ };
937
+ })
938
+ .catch(commonErrorCallback());
939
+ },
940
+ getExternalTableOrdersFromPayment({ commit }, { tablePaymentId }) {
941
+ return $http
942
+ .get(`/api/table-payments`, { params: { tablePaymentId } })
943
+ .then((res) => {
944
+ commit("setExternalTableOrders", res.data.data);
945
+ return {
946
+ type: "success",
947
+ msg: "ok",
948
+ };
949
+ })
950
+ .catch(commonErrorCallback());
951
+ },
952
+ };
758
953
  export default {
759
- namespaced: true,
760
- state,
761
- mutations,
762
- actions
954
+ namespaced: true,
955
+ state,
956
+ mutations,
957
+ actions,
763
958
  };