orderiom-api-package 0.2.44 → 0.2.46
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/order.js +28 -2
package/package.json
CHANGED
package/src/modules/order.js
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
|
|
3
|
+
const restaurantId = process.env.VUE_APP_RESTAURANT_ID;
|
|
4
|
+
|
|
5
|
+
function calculateBasketIdParameter(isLogin) {
|
|
6
|
+
if(isLogin) return undefined;
|
|
7
|
+
// localStorage might fail
|
|
8
|
+
let baskets = [];
|
|
9
|
+
try{
|
|
10
|
+
baskets = JSON.parse(localStorage.getItem("basket")) || [];
|
|
11
|
+
}catch(e){
|
|
12
|
+
console.error(e);
|
|
13
|
+
throw new Error('Basket not found');
|
|
14
|
+
}
|
|
15
|
+
const foundBasket = baskets.find(basket => basket.restaurantId === restaurantId);
|
|
16
|
+
if(!foundBasket){
|
|
17
|
+
throw new Error('Basket not found');
|
|
18
|
+
}
|
|
19
|
+
return foundBasket.basketId;
|
|
20
|
+
}
|
|
21
|
+
|
|
3
22
|
const state = () => ({
|
|
4
23
|
productOrder: null,
|
|
5
24
|
userOrder: {},
|
|
@@ -710,8 +729,14 @@ const actions = {
|
|
|
710
729
|
}
|
|
711
730
|
});
|
|
712
731
|
},
|
|
713
|
-
getShippingPrice({ commit }, data) {
|
|
714
|
-
|
|
732
|
+
getShippingPrice({ commit, rootState }, data) {
|
|
733
|
+
let basketId = undefined;
|
|
734
|
+
try{
|
|
735
|
+
basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken);
|
|
736
|
+
} catch(e) {
|
|
737
|
+
console.error(e);
|
|
738
|
+
return { type: 'error', msg: 'Basket not found' }
|
|
739
|
+
}
|
|
715
740
|
if (!data.postalCode || !data.deliveryType) {
|
|
716
741
|
return
|
|
717
742
|
}
|
|
@@ -721,6 +746,7 @@ const actions = {
|
|
|
721
746
|
deliveryType: data.deliveryType,
|
|
722
747
|
postalCode: data.postalCode,
|
|
723
748
|
restaurantId: data.restaurantId,
|
|
749
|
+
basketId:basketId
|
|
724
750
|
},
|
|
725
751
|
})
|
|
726
752
|
.then((res) => {
|