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