orderiom-api-package 0.4.7 → 0.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/modules/auth.js +39 -55
- package/src/modules/order.js +302 -250
package/package.json
CHANGED
package/src/modules/auth.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {commonErrorCallback, $http, calculateBasketIdParameter, restaurantIdEnv} from '../common';
|
|
2
2
|
|
|
3
3
|
const state = {
|
|
4
4
|
publicToken: null,
|
|
@@ -92,18 +92,17 @@ const actions = {
|
|
|
92
92
|
});
|
|
93
93
|
dispatch("fetchUser");
|
|
94
94
|
const basketData = JSON.parse(window.localStorage.getItem("basket"));
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
|
|
96
|
+
const restaurantId = authData.restaurantId || restaurantIdEnv;
|
|
97
|
+
if(Array.isArray(basketData) && restaurantId){
|
|
98
|
+
for(let i = 0; i < basketData.length; i++){
|
|
99
|
+
if (basketData[i].restaurantId == restaurantId) {
|
|
100
|
+
dispatch('assignBasket', restaurantId);
|
|
101
|
+
break;
|
|
100
102
|
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
if (authData.restaurantId &&
|
|
104
|
-
basketData && basketData.length && hasTarget) {
|
|
105
|
-
dispatch('assignBasket', authData.restaurantId)
|
|
103
|
+
}
|
|
106
104
|
}
|
|
105
|
+
|
|
107
106
|
return {
|
|
108
107
|
type: 'success',
|
|
109
108
|
msg: 'ok'
|
|
@@ -126,12 +125,12 @@ const actions = {
|
|
|
126
125
|
}
|
|
127
126
|
)
|
|
128
127
|
.then((res) => {
|
|
129
|
-
const restaurantId = authData.restaurantId
|
|
128
|
+
const restaurantId = authData.restaurantId || restaurantIdEnv;
|
|
130
129
|
const ordermood = authData.ordermood ? { ordermood: authData.ordermood } : {}
|
|
131
130
|
dispatch("login", {
|
|
132
131
|
email: authData.email,
|
|
133
132
|
password: authData.password,
|
|
134
|
-
|
|
133
|
+
restaurantId: restaurantId ? restaurantId : undefined,
|
|
135
134
|
...ordermood
|
|
136
135
|
});
|
|
137
136
|
return {
|
|
@@ -160,21 +159,17 @@ const actions = {
|
|
|
160
159
|
commit("authUser", { privateToken, expires_at });
|
|
161
160
|
dispatch('fetchUser')
|
|
162
161
|
},
|
|
163
|
-
logout({ commit, state, dispatch },
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (!state.privateToken) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
162
|
+
logout({ commit, state, dispatch }, restaurantId) {
|
|
163
|
+
if (!state.privateToken) return;
|
|
169
164
|
return $http
|
|
170
165
|
.get("api/auth/logout", {
|
|
171
166
|
params: {
|
|
172
|
-
|
|
167
|
+
restaurantId
|
|
173
168
|
}
|
|
174
169
|
})
|
|
175
170
|
.then(() => {
|
|
176
171
|
commit("clearAuthData");
|
|
177
|
-
dispatch('unassignBasket',
|
|
172
|
+
dispatch('unassignBasket', restaurantId)
|
|
178
173
|
// commit("product/SetShoppingCart", [], { root: true });
|
|
179
174
|
// commit("product/SetSubtotalPrice", null, { root: true });
|
|
180
175
|
return true
|
|
@@ -201,42 +196,32 @@ const actions = {
|
|
|
201
196
|
},
|
|
202
197
|
assignBasket({ dispatch }, restaurantId) {
|
|
203
198
|
const basket = JSON.parse(localStorage.getItem("basket"));
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
199
|
+
if(!basket || !Array.isArray(basket)) return;
|
|
200
|
+
const foundBasket = basket.find(item => Number(item.restaurantId) === Number(restaurantId || restaurantIdEnv))
|
|
201
|
+
const basketId = foundBasket ? foundBasket.basketId : undefined;
|
|
202
|
+
|
|
203
|
+
basketId && $http
|
|
204
|
+
.post(`api/basket/assign-basket`, null, { params: { basketId: basketId, restaurantId: restaurantId } })
|
|
205
|
+
.then(() => {
|
|
206
|
+
dispatch('product/getBasket', restaurantId, { root: true })
|
|
207
|
+
})
|
|
208
|
+
.catch(
|
|
209
|
+
commonErrorCallback()
|
|
210
|
+
);
|
|
216
211
|
},
|
|
217
212
|
unassignBasket({ }, restaurantId) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
msg: 'ok'
|
|
230
|
-
};
|
|
231
|
-
})
|
|
232
|
-
.catch(
|
|
233
|
-
commonErrorCallback()
|
|
234
|
-
);
|
|
213
|
+
const basket = JSON.parse(localStorage.getItem("basket"));
|
|
214
|
+
if(!basket || !Array.isArray(basket)) return;
|
|
215
|
+
let baskets = [];
|
|
216
|
+
|
|
217
|
+
if (restaurantId || restaurantIdEnv) {
|
|
218
|
+
const foundBasket = basket.find(item => Number(item.restaurantId) === Number(restaurantId || restaurantIdEnv))
|
|
219
|
+
const basketId = foundBasket ? foundBasket.basketId : undefined;
|
|
220
|
+
|
|
221
|
+
if(basketId) baskets.push(basketId);
|
|
222
|
+
} else {
|
|
223
|
+
baskets = basket.map(m => m.basketId)
|
|
235
224
|
}
|
|
236
|
-
else {
|
|
237
|
-
let basket = JSON.parse(localStorage.getItem("basket"));
|
|
238
|
-
if (!basket.length) return
|
|
239
|
-
let baskets = basket.map(m => m.basketId)
|
|
240
225
|
for (let i = 0; i < baskets.length; i++) {
|
|
241
226
|
$http
|
|
242
227
|
.post(`api/basket/unassigned-basket`, null, { params: { basketId: baskets[i] } })
|
|
@@ -250,7 +235,6 @@ const actions = {
|
|
|
250
235
|
commonErrorCallback()
|
|
251
236
|
);
|
|
252
237
|
}
|
|
253
|
-
}
|
|
254
238
|
},
|
|
255
239
|
restaurantInfo({ commit }, restaurantId) {
|
|
256
240
|
return $http
|
package/src/modules/order.js
CHANGED
|
@@ -136,14 +136,17 @@ const actions = {
|
|
|
136
136
|
.catch(commonErrorCallback("There was an error in creating basket"));
|
|
137
137
|
},
|
|
138
138
|
setTable({ rootState }, data) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
)
|
|
145
|
-
|
|
146
|
-
|
|
139
|
+
let basketId = undefined;
|
|
140
|
+
try {
|
|
141
|
+
basketId = calculateBasketIdParameter(
|
|
142
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
143
|
+
data.restaurantId
|
|
144
|
+
);
|
|
145
|
+
} catch (e) {
|
|
146
|
+
console.error(e);
|
|
147
|
+
return { type: "error", msg: "Basket not found" };
|
|
148
|
+
}
|
|
149
|
+
|
|
147
150
|
let table = null;
|
|
148
151
|
if (data.tableId) {
|
|
149
152
|
table = { tableId: data.tableId };
|
|
@@ -156,7 +159,7 @@ const actions = {
|
|
|
156
159
|
return $http
|
|
157
160
|
.post("api/basket/set-table", {
|
|
158
161
|
restaurantId: data.restaurantId,
|
|
159
|
-
|
|
162
|
+
basketId,
|
|
160
163
|
...table,
|
|
161
164
|
qrcode: data.qrcode,
|
|
162
165
|
})
|
|
@@ -173,14 +176,16 @@ const actions = {
|
|
|
173
176
|
? null
|
|
174
177
|
: rootState.orderiomApiPackage.product.ShoppingCart.find(f => f.basketProductId === data.basketProductId);
|
|
175
178
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
)
|
|
182
|
-
|
|
183
|
-
|
|
179
|
+
let basketId = undefined;
|
|
180
|
+
try {
|
|
181
|
+
basketId = calculateBasketIdParameter(
|
|
182
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
183
|
+
data.restaurantId
|
|
184
|
+
);
|
|
185
|
+
} catch (e) {
|
|
186
|
+
console.error(e);
|
|
187
|
+
return { type: "error", msg: "Basket not found" };
|
|
188
|
+
}
|
|
184
189
|
|
|
185
190
|
if (basketProduct) basketProduct.changingQuantity = true;
|
|
186
191
|
|
|
@@ -188,7 +193,7 @@ const actions = {
|
|
|
188
193
|
|
|
189
194
|
$http
|
|
190
195
|
.post("api/basket/add", {
|
|
191
|
-
|
|
196
|
+
basketId,
|
|
192
197
|
productId: data.productId,
|
|
193
198
|
quantity: !data.quantity || data.quantity < 1 ? 1 : data.quantity,
|
|
194
199
|
attributeItems: data.attributeItems.length
|
|
@@ -220,20 +225,22 @@ const actions = {
|
|
|
220
225
|
};
|
|
221
226
|
}
|
|
222
227
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
)
|
|
229
|
-
|
|
230
|
-
|
|
228
|
+
let basketId = undefined;
|
|
229
|
+
try {
|
|
230
|
+
basketId = calculateBasketIdParameter(
|
|
231
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
232
|
+
data.restaurantId
|
|
233
|
+
);
|
|
234
|
+
} catch (e) {
|
|
235
|
+
console.error(e);
|
|
236
|
+
return { type: "error", msg: "Basket not found" };
|
|
237
|
+
}
|
|
231
238
|
|
|
232
239
|
basketProduct.changingQuantity = true;
|
|
233
240
|
$http
|
|
234
241
|
.get("api/basket/remove", {
|
|
235
242
|
params: {
|
|
236
|
-
|
|
243
|
+
basketId,
|
|
237
244
|
basketProductId: basketProduct.basketProductId,
|
|
238
245
|
restaurantId: data.restaurantId,
|
|
239
246
|
},
|
|
@@ -262,20 +269,22 @@ const actions = {
|
|
|
262
269
|
};
|
|
263
270
|
}
|
|
264
271
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
)
|
|
271
|
-
|
|
272
|
-
|
|
272
|
+
let basketId = undefined;
|
|
273
|
+
try {
|
|
274
|
+
basketId = calculateBasketIdParameter(
|
|
275
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
276
|
+
data.restaurantId
|
|
277
|
+
);
|
|
278
|
+
} catch (e) {
|
|
279
|
+
console.error(e);
|
|
280
|
+
return { type: "error", msg: "Basket not found" };
|
|
281
|
+
}
|
|
273
282
|
|
|
274
283
|
basketProduct.changingQuantity = true;
|
|
275
284
|
$http
|
|
276
285
|
.get("api/basket/remove", {
|
|
277
286
|
params: {
|
|
278
|
-
|
|
287
|
+
basketId,
|
|
279
288
|
basketProductId: data.basketProductId,
|
|
280
289
|
restaurantId: data.restaurantId,
|
|
281
290
|
},
|
|
@@ -303,20 +312,22 @@ const actions = {
|
|
|
303
312
|
};
|
|
304
313
|
}
|
|
305
314
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
)
|
|
312
|
-
|
|
313
|
-
|
|
315
|
+
let basketId = undefined;
|
|
316
|
+
try {
|
|
317
|
+
basketId = calculateBasketIdParameter(
|
|
318
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
319
|
+
data.restaurantId
|
|
320
|
+
);
|
|
321
|
+
} catch (e) {
|
|
322
|
+
console.error(e);
|
|
323
|
+
return { type: "error", msg: "Basket not found" };
|
|
324
|
+
}
|
|
314
325
|
|
|
315
326
|
basketProduct.deleting = true;
|
|
316
327
|
return $http
|
|
317
328
|
.get("api/basket/delete-basket-product", {
|
|
318
329
|
params: {
|
|
319
|
-
|
|
330
|
+
basketId,
|
|
320
331
|
basketProductId: basketProduct.basketProductId,
|
|
321
332
|
restaurantId: data.restaurantId,
|
|
322
333
|
},
|
|
@@ -345,20 +356,22 @@ const actions = {
|
|
|
345
356
|
};
|
|
346
357
|
}
|
|
347
358
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
)
|
|
354
|
-
|
|
355
|
-
|
|
359
|
+
let basketId = undefined;
|
|
360
|
+
try {
|
|
361
|
+
basketId = calculateBasketIdParameter(
|
|
362
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
363
|
+
data.restaurantId
|
|
364
|
+
);
|
|
365
|
+
} catch (e) {
|
|
366
|
+
console.error(e);
|
|
367
|
+
return { type: "error", msg: "Basket not found" };
|
|
368
|
+
}
|
|
356
369
|
|
|
357
370
|
basketProduct.deleting = true;
|
|
358
371
|
$http
|
|
359
372
|
.get("api/basket/delete-basket-product", {
|
|
360
373
|
params: {
|
|
361
|
-
|
|
374
|
+
basketId,
|
|
362
375
|
basketProductId: data.basketProductId,
|
|
363
376
|
restaurantId: data.restaurantId,
|
|
364
377
|
},
|
|
@@ -378,21 +391,23 @@ const actions = {
|
|
|
378
391
|
? null
|
|
379
392
|
: rootState.orderiomApiPackage.product.ShoppingCart.find(f => f.basketProductId === Number(data.basketProductId));
|
|
380
393
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
)
|
|
387
|
-
|
|
388
|
-
|
|
394
|
+
let basketId = undefined;
|
|
395
|
+
try {
|
|
396
|
+
basketId = calculateBasketIdParameter(
|
|
397
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
398
|
+
data.restaurantId
|
|
399
|
+
);
|
|
400
|
+
} catch (e) {
|
|
401
|
+
console.error(e);
|
|
402
|
+
return { type: "error", msg: "Basket not found" };
|
|
403
|
+
}
|
|
389
404
|
|
|
390
405
|
data.quantity = parseInt(data.quantity);
|
|
391
406
|
|
|
392
407
|
if (basketProduct) basketProduct.changingQuantity = true;
|
|
393
408
|
return $http
|
|
394
409
|
.post("api/basket/add-product-package-items", {
|
|
395
|
-
|
|
410
|
+
basketId,
|
|
396
411
|
...data,
|
|
397
412
|
quantity: !data.quantity || data.quantity < 1 ? 1 : data.quantity,
|
|
398
413
|
})
|
|
@@ -411,14 +426,16 @@ const actions = {
|
|
|
411
426
|
? null
|
|
412
427
|
: rootState.orderiomApiPackage.product.ShoppingCart.find(f => f.basketProductId === data.basketProductId);
|
|
413
428
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
)
|
|
420
|
-
|
|
421
|
-
|
|
429
|
+
let basketId = undefined;
|
|
430
|
+
try {
|
|
431
|
+
basketId = calculateBasketIdParameter(
|
|
432
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
433
|
+
data.restaurantId
|
|
434
|
+
);
|
|
435
|
+
} catch (e) {
|
|
436
|
+
console.error(e);
|
|
437
|
+
return { type: "error", msg: "Basket not found" };
|
|
438
|
+
}
|
|
422
439
|
|
|
423
440
|
if (basketProduct) basketProduct.changingQuantity = true;
|
|
424
441
|
|
|
@@ -427,7 +444,7 @@ const actions = {
|
|
|
427
444
|
$http
|
|
428
445
|
.post("api/basket/add-attribute-items", {
|
|
429
446
|
restaurantId: data.restaurantId,
|
|
430
|
-
|
|
447
|
+
basketId,
|
|
431
448
|
basketProductId: data.basketProductId,
|
|
432
449
|
attributeItems: data.attributeItems.length
|
|
433
450
|
? data.attributeItems
|
|
@@ -451,14 +468,16 @@ const actions = {
|
|
|
451
468
|
? null
|
|
452
469
|
: rootState.orderiomApiPackage.product.ShoppingCart.find(f => f.basketProductId === data.basketProductId);
|
|
453
470
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
)
|
|
460
|
-
|
|
461
|
-
|
|
471
|
+
let basketId = undefined;
|
|
472
|
+
try {
|
|
473
|
+
basketId = calculateBasketIdParameter(
|
|
474
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
475
|
+
data.restaurantId
|
|
476
|
+
);
|
|
477
|
+
} catch (e) {
|
|
478
|
+
console.error(e);
|
|
479
|
+
return { type: "error", msg: "Basket not found" };
|
|
480
|
+
}
|
|
462
481
|
|
|
463
482
|
if (basketProduct) basketProduct.changingQuantity = true;
|
|
464
483
|
|
|
@@ -467,7 +486,7 @@ const actions = {
|
|
|
467
486
|
$http
|
|
468
487
|
.post("api/basket/remove-attribute-items", {
|
|
469
488
|
restaurantId: data.restaurantId,
|
|
470
|
-
|
|
489
|
+
basketId,
|
|
471
490
|
basketProductId: data.basketProductId,
|
|
472
491
|
attributeItems: data.attributeItems.length
|
|
473
492
|
? data.attributeItems
|
|
@@ -487,17 +506,20 @@ const actions = {
|
|
|
487
506
|
});
|
|
488
507
|
},
|
|
489
508
|
addAddress({ rootState }, data) {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
)
|
|
496
|
-
|
|
497
|
-
|
|
509
|
+
let basketId = undefined;
|
|
510
|
+
try {
|
|
511
|
+
basketId = calculateBasketIdParameter(
|
|
512
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
513
|
+
data.restaurantId
|
|
514
|
+
);
|
|
515
|
+
} catch (e) {
|
|
516
|
+
console.error(e);
|
|
517
|
+
return { type: "error", msg: "Basket not found" };
|
|
518
|
+
}
|
|
519
|
+
|
|
498
520
|
return $http
|
|
499
521
|
.post("api/basket/add-address", {
|
|
500
|
-
|
|
522
|
+
basketId,
|
|
501
523
|
restaurantId: data.restaurantId,
|
|
502
524
|
userInfo: data.userInfo,
|
|
503
525
|
})
|
|
@@ -507,18 +529,21 @@ const actions = {
|
|
|
507
529
|
.catch(commonErrorCallback());
|
|
508
530
|
},
|
|
509
531
|
checkAddress({ rootState }, data) {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
)
|
|
516
|
-
|
|
517
|
-
|
|
532
|
+
let basketId = undefined;
|
|
533
|
+
try {
|
|
534
|
+
basketId = calculateBasketIdParameter(
|
|
535
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
536
|
+
data.restaurantId
|
|
537
|
+
);
|
|
538
|
+
} catch (e) {
|
|
539
|
+
console.error(e);
|
|
540
|
+
return { type: "error", msg: "Basket not found" };
|
|
541
|
+
}
|
|
542
|
+
|
|
518
543
|
return $http
|
|
519
544
|
.get("api/order/check-address", {
|
|
520
545
|
params: {
|
|
521
|
-
|
|
546
|
+
basketId,
|
|
522
547
|
restaurantId: data.restaurantId,
|
|
523
548
|
postalCode: data.postalCode,
|
|
524
549
|
deliveryType: data.deliveryType,
|
|
@@ -540,80 +565,81 @@ const actions = {
|
|
|
540
565
|
}
|
|
541
566
|
},
|
|
542
567
|
createOrder({ commit, rootState }, data) {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
.post("api/order/create-order", {
|
|
554
|
-
...basketId,
|
|
555
|
-
...restaurantID,
|
|
556
|
-
paymentType: data.paymentType,
|
|
557
|
-
...(data.paymentType === "payFix" && {
|
|
558
|
-
qrCode: data.payfix_qrcode,
|
|
559
|
-
pin: data.payfix_pin,
|
|
560
|
-
}),
|
|
561
|
-
tablePaymentId: data.tablePaymentId ? data.tablePaymentId : null,
|
|
562
|
-
externalBasketItems: data.externalBasketItems ? data.externalBasketItems: null
|
|
563
|
-
})
|
|
564
|
-
.then((res) => {
|
|
565
|
-
// localStorage.setItem("orderId", res.data.data.order.id);
|
|
566
|
-
// commit('setproductOrder', res.data.data.product)
|
|
567
|
-
// commit('settotalPriceOrder', res.data.data.order.total_price)
|
|
568
|
-
// commit('setorder', res.data.data.order)
|
|
569
|
-
// commit('setuserOrder', JSON.parse(res.data.data.order.user_details));
|
|
570
|
-
// commit('setshippigPriceOrder', res.data.data.order.shipping_price);
|
|
568
|
+
let basketId = undefined;
|
|
569
|
+
try {
|
|
570
|
+
basketId = calculateBasketIdParameter(
|
|
571
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
572
|
+
data.restaurantId
|
|
573
|
+
);
|
|
574
|
+
} catch (e) {
|
|
575
|
+
console.error(e);
|
|
576
|
+
return { type: "error", msg: "Basket not found" };
|
|
577
|
+
}
|
|
571
578
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
data
|
|
576
|
-
data.
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
});
|
|
590
|
-
} else {
|
|
591
|
-
window.location = res.data.data.paymentLink;
|
|
592
|
-
}
|
|
579
|
+
return $http.post("api/order/create-order", {
|
|
580
|
+
basketId,
|
|
581
|
+
restaurantId: data.restaurantId || undefined,
|
|
582
|
+
paymentType: data.paymentType,
|
|
583
|
+
...(data.paymentType === "payFix" && {
|
|
584
|
+
qrCode: data.payfix_qrcode,
|
|
585
|
+
pin: data.payfix_pin,
|
|
586
|
+
}),
|
|
587
|
+
tablePaymentId: data.tablePaymentId ? data.tablePaymentId : null,
|
|
588
|
+
externalBasketItems: data.externalBasketItems ? data.externalBasketItems : null
|
|
589
|
+
}).then(res => {
|
|
590
|
+
// localStorage.setItem("orderId", res.data.data.order.id);
|
|
591
|
+
// commit('setproductOrder', res.data.data.product)
|
|
592
|
+
// commit('settotalPriceOrder', res.data.data.order.total_price)
|
|
593
|
+
// commit('setorder', res.data.data.order)
|
|
594
|
+
// commit('setuserOrder', JSON.parse(res.data.data.order.user_details));
|
|
595
|
+
// commit('setshippigPriceOrder', res.data.data.order.shipping_price);
|
|
593
596
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
597
|
+
if (
|
|
598
|
+
(
|
|
599
|
+
res.data.data.paymentLink.includes("/paymentstatus/?") ||
|
|
600
|
+
res.data.data.paymentLink.includes("/paymentstatus?")
|
|
601
|
+
) &&
|
|
602
|
+
data.$router &&
|
|
603
|
+
data.routeName
|
|
604
|
+
) {
|
|
605
|
+
data.$router.push({
|
|
606
|
+
name: data.routeName,
|
|
607
|
+
query: res.data.data.paymentLink
|
|
608
|
+
.split("?")[1]
|
|
609
|
+
.split("&")
|
|
610
|
+
.map((query) => query.split("="))
|
|
611
|
+
.reduce((result, element) => {
|
|
612
|
+
if (!element) return result;
|
|
613
|
+
result[element[0]] = element[1];
|
|
614
|
+
return result;
|
|
615
|
+
}, {}),
|
|
616
|
+
});
|
|
617
|
+
} else {
|
|
618
|
+
window.location = res.data.data.paymentLink;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
const basketData = JSON.parse(localStorage.getItem("basket"));
|
|
622
|
+
if (basketData) {
|
|
623
|
+
const index = basketId
|
|
624
|
+
? basketData.findIndex(item => Number(item.basketId) === Number(basketId))
|
|
625
|
+
: basketData.findIndex(item => Number(item.restaurantId) === Number(data.restaurantId || restaurantIdEnv))
|
|
626
|
+
if (index > -1) {
|
|
627
|
+
basketData.splice(index, 1);
|
|
628
|
+
localStorage.setItem("basket", JSON.stringify(basketData));
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
commit("product/SetSubtotalPrice", "0.00", {root: true});
|
|
633
|
+
commit("product/SetShoppingCart", [], {root: true});
|
|
634
|
+
commit("product/setBasketInfo", {}, {root: true});
|
|
635
|
+
commit("product/setDeliveryTime", "", {root: true});
|
|
636
|
+
commit("product/SetTotalPrice", "0.00", { root: true });
|
|
637
|
+
|
|
638
|
+
return {
|
|
639
|
+
type: "success",
|
|
640
|
+
msg: "ok",
|
|
641
|
+
};
|
|
642
|
+
}).catch(commonErrorCallback());
|
|
617
643
|
},
|
|
618
644
|
getOrder({ commit }, orderId) {
|
|
619
645
|
return $http
|
|
@@ -656,14 +682,17 @@ const actions = {
|
|
|
656
682
|
.catch(commonErrorCallback());
|
|
657
683
|
},
|
|
658
684
|
preparePayment({ rootState }, data) {
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
)
|
|
665
|
-
|
|
666
|
-
|
|
685
|
+
let basketId = undefined;
|
|
686
|
+
try {
|
|
687
|
+
basketId = calculateBasketIdParameter(
|
|
688
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
689
|
+
data.restaurantId
|
|
690
|
+
);
|
|
691
|
+
} catch (e) {
|
|
692
|
+
console.error(e);
|
|
693
|
+
return { type: "error", msg: "Basket not found" };
|
|
694
|
+
}
|
|
695
|
+
|
|
667
696
|
const restaurantID = data.restaurantId
|
|
668
697
|
? { restaurantId: data.restaurantId }
|
|
669
698
|
: {};
|
|
@@ -671,7 +700,7 @@ const actions = {
|
|
|
671
700
|
$http
|
|
672
701
|
.get("api/payment/prepare", {
|
|
673
702
|
params: {
|
|
674
|
-
|
|
703
|
+
basketId,
|
|
675
704
|
...restaurantID,
|
|
676
705
|
},
|
|
677
706
|
})
|
|
@@ -706,6 +735,10 @@ const actions = {
|
|
|
706
735
|
.catch(commonErrorCallback());
|
|
707
736
|
},
|
|
708
737
|
getShippingPrice({ commit, rootState }, data) {
|
|
738
|
+
if (!data.postalCode || !data.deliveryType) {
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
|
|
709
742
|
let basketId = undefined;
|
|
710
743
|
try {
|
|
711
744
|
basketId = calculateBasketIdParameter(
|
|
@@ -716,9 +749,7 @@ const actions = {
|
|
|
716
749
|
console.error(e);
|
|
717
750
|
return { type: "error", msg: "Basket not found" };
|
|
718
751
|
}
|
|
719
|
-
|
|
720
|
-
return;
|
|
721
|
-
}
|
|
752
|
+
|
|
722
753
|
return $http
|
|
723
754
|
.get(`api/restaurant/shipping-price`, {
|
|
724
755
|
params: {
|
|
@@ -753,21 +784,25 @@ const actions = {
|
|
|
753
784
|
.catch(commonErrorCallback());
|
|
754
785
|
},
|
|
755
786
|
getTotalPrice({ commit, rootState }, data) {
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
787
|
+
if (!data.postalCode || !data.deliveryType) {
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
let basketId = undefined;
|
|
792
|
+
try {
|
|
793
|
+
basketId = calculateBasketIdParameter(
|
|
794
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
795
|
+
data.restaurantId
|
|
796
|
+
);
|
|
797
|
+
} catch (e) {
|
|
798
|
+
console.error(e);
|
|
799
|
+
return { type: "error", msg: "Basket not found" };
|
|
800
|
+
}
|
|
801
|
+
|
|
767
802
|
return $http
|
|
768
803
|
.get(`api/basket/total-price`, {
|
|
769
804
|
params: {
|
|
770
|
-
|
|
805
|
+
basketId,
|
|
771
806
|
deliveryType: data.deliveryType,
|
|
772
807
|
postalCode: data.postalCode,
|
|
773
808
|
restaurantId: data.restaurantId,
|
|
@@ -783,20 +818,20 @@ const actions = {
|
|
|
783
818
|
.catch(commonErrorCallback());
|
|
784
819
|
},
|
|
785
820
|
addDeliveryTimeToBasket({ dispatch, rootState }, data) {
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
821
|
+
let basketId = undefined;
|
|
822
|
+
try {
|
|
823
|
+
basketId = calculateBasketIdParameter(
|
|
824
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
825
|
+
data.restaurantId
|
|
826
|
+
);
|
|
827
|
+
} catch (e) {
|
|
828
|
+
console.error(e);
|
|
829
|
+
return { type: "error", msg: "Basket not found" };
|
|
830
|
+
}
|
|
831
|
+
|
|
797
832
|
return $http
|
|
798
833
|
.post("api/basket/add-delivery-time", {
|
|
799
|
-
|
|
834
|
+
basketId,
|
|
800
835
|
delivery_time:
|
|
801
836
|
data.date && data.time ? data.date + " " + data.time : null,
|
|
802
837
|
deliveryType: data.deliveryType,
|
|
@@ -822,20 +857,23 @@ const actions = {
|
|
|
822
857
|
.catch(commonErrorCallback());
|
|
823
858
|
},
|
|
824
859
|
addVoucher({ rootState, dispatch }, data) {
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
)
|
|
831
|
-
|
|
832
|
-
|
|
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
|
+
}
|
|
870
|
+
|
|
833
871
|
return $http
|
|
834
872
|
.post("api/basket/add-voucher-to-basket", null, {
|
|
835
873
|
params: {
|
|
836
874
|
voucherCode: data.voucherCode,
|
|
837
875
|
restaurantId: data.restaurantId,
|
|
838
|
-
|
|
876
|
+
basketId,
|
|
839
877
|
},
|
|
840
878
|
})
|
|
841
879
|
.then((result) => {
|
|
@@ -848,17 +886,21 @@ const actions = {
|
|
|
848
886
|
.catch(commonErrorCallback());
|
|
849
887
|
},
|
|
850
888
|
removeVoucher({ rootState, dispatch }, restaurantId) {
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
889
|
+
let basketId = undefined;
|
|
890
|
+
try {
|
|
891
|
+
basketId = calculateBasketIdParameter(
|
|
892
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
893
|
+
restaurantId
|
|
894
|
+
);
|
|
895
|
+
} catch (e) {
|
|
896
|
+
console.error(e);
|
|
897
|
+
return { type: "error", msg: "Basket not found" };
|
|
898
|
+
}
|
|
899
|
+
|
|
858
900
|
return $http
|
|
859
901
|
.get("api/basket/remove-voucher-from-basket", {
|
|
860
902
|
params: {
|
|
861
|
-
|
|
903
|
+
basketId,
|
|
862
904
|
restaurantId: restaurantId,
|
|
863
905
|
},
|
|
864
906
|
})
|
|
@@ -872,17 +914,20 @@ const actions = {
|
|
|
872
914
|
.catch(commonErrorCallback());
|
|
873
915
|
},
|
|
874
916
|
addTip({ rootState, dispatch }, data) {
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
)
|
|
881
|
-
|
|
882
|
-
|
|
917
|
+
let basketId = undefined;
|
|
918
|
+
try {
|
|
919
|
+
basketId = calculateBasketIdParameter(
|
|
920
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
921
|
+
data.restaurantId
|
|
922
|
+
);
|
|
923
|
+
} catch (e) {
|
|
924
|
+
console.error(e);
|
|
925
|
+
return { type: "error", msg: "Basket not found" };
|
|
926
|
+
}
|
|
927
|
+
|
|
883
928
|
return $http
|
|
884
929
|
.post("api/basket/add-tip", {
|
|
885
|
-
|
|
930
|
+
basketId,
|
|
886
931
|
restaurantId: data.restaurantId,
|
|
887
932
|
tip_price: data.tip_price,
|
|
888
933
|
})
|
|
@@ -896,16 +941,20 @@ const actions = {
|
|
|
896
941
|
.catch(commonErrorCallback());
|
|
897
942
|
},
|
|
898
943
|
removeTip({ rootState, dispatch }, restaurantId) {
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
944
|
+
let basketId = undefined;
|
|
945
|
+
try {
|
|
946
|
+
basketId = calculateBasketIdParameter(
|
|
947
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
948
|
+
restaurantId
|
|
949
|
+
);
|
|
950
|
+
} catch (e) {
|
|
951
|
+
console.error(e);
|
|
952
|
+
return { type: "error", msg: "Basket not found" };
|
|
953
|
+
}
|
|
954
|
+
|
|
906
955
|
return $http
|
|
907
956
|
.put("api/basket/remove-tip-from-basket", {
|
|
908
|
-
|
|
957
|
+
basketId,
|
|
909
958
|
restaurantId: restaurantId,
|
|
910
959
|
})
|
|
911
960
|
.then((result) => {
|
|
@@ -918,19 +967,22 @@ const actions = {
|
|
|
918
967
|
.catch(commonErrorCallback());
|
|
919
968
|
},
|
|
920
969
|
checkOrderValidity({ rootState }, data) {
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
)
|
|
927
|
-
|
|
928
|
-
|
|
970
|
+
let basketId = undefined;
|
|
971
|
+
try {
|
|
972
|
+
basketId = calculateBasketIdParameter(
|
|
973
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
974
|
+
data.restaurantId
|
|
975
|
+
);
|
|
976
|
+
} catch (e) {
|
|
977
|
+
console.error(e);
|
|
978
|
+
return { type: "error", msg: "Basket not found" };
|
|
979
|
+
}
|
|
980
|
+
|
|
929
981
|
return $http
|
|
930
982
|
.post("api/order/is-valid", null, {
|
|
931
983
|
params: {
|
|
932
984
|
restaurantId: data.restaurantId,
|
|
933
|
-
|
|
985
|
+
basketId,
|
|
934
986
|
},
|
|
935
987
|
})
|
|
936
988
|
.then((result) => {
|