orderiom-api-package 0.3.42 → 0.3.44

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