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