orderiom-api-package 0.2.55 → 0.2.57
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/common.js +33 -0
- package/src/modules/order.js +20 -1
- package/src/modules/product.js +14 -41
package/package.json
CHANGED
package/src/common.js
CHANGED
|
@@ -36,4 +36,37 @@ export function calculateBasketIdParameter(isLogin) {
|
|
|
36
36
|
throw new Error('Basket not found');
|
|
37
37
|
}
|
|
38
38
|
return foundBasket.basketId;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function updateBasket({commit}, basketId, res){
|
|
42
|
+
const basketInfo = res.data.data;
|
|
43
|
+
commit('product/setBasketInfo', basketInfo);
|
|
44
|
+
|
|
45
|
+
// TODO: why two separate states use same value?
|
|
46
|
+
commit('product/SetSubtotalPrice', basketInfo.totalPrice);
|
|
47
|
+
commit('product/SetTotalPrice', basketInfo.totalPrice);
|
|
48
|
+
|
|
49
|
+
commit('product/SetShoppingCart', basketInfo.products);
|
|
50
|
+
commit('product/setDeliveryTime', basketInfo.deliveryTime);
|
|
51
|
+
commit('product/setVoucherCode', basketInfo.voucher_code);
|
|
52
|
+
commit('product/setVoucherValue', basketInfo.voucherValue);
|
|
53
|
+
commit('product/setTotalWithDiscount', basketInfo.totalWithDiscount);
|
|
54
|
+
commit('product/setDelivertType', basketInfo.deliveryType);
|
|
55
|
+
commit('product/setPostalCode', basketInfo.postalCode);
|
|
56
|
+
commit('product/setTip', basketInfo.tip);
|
|
57
|
+
commit('product/setshippingPrice', basketInfo.shipping_price);
|
|
58
|
+
|
|
59
|
+
if (parseInt(basketInfo.id) !== parseInt(basketId)) {
|
|
60
|
+
const baskets = JSON.parse(localStorage.getItem('basket'));
|
|
61
|
+
const basketIndex = baskets.findIndex(basket => parseInt(basket.restaurantId) === restaurantId);
|
|
62
|
+
if (basketIndex > -1) baskets.splice(basketIndex, 1);
|
|
63
|
+
baskets.push({
|
|
64
|
+
restaurantId,
|
|
65
|
+
basketId: basketInfo.id,
|
|
66
|
+
});
|
|
67
|
+
localStorage.setItem('basket', JSON.stringify(baskets));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
commit('product/basketLoadedOnce');
|
|
71
|
+
return true;
|
|
39
72
|
}
|
package/src/modules/order.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
-
import {
|
|
2
|
+
import {commonErrorCallback, calculateBasketIdParameter, restaurantId, updateBasket} from '../common';
|
|
3
3
|
|
|
4
4
|
const state = () => ({
|
|
5
5
|
productOrder: null,
|
|
@@ -693,6 +693,25 @@ const actions = {
|
|
|
693
693
|
}).catch(
|
|
694
694
|
commonErrorCallback()
|
|
695
695
|
);
|
|
696
|
+
},
|
|
697
|
+
editCartProductExtraInfo({rootState, commit}, {basketProductId, extraInfo}){
|
|
698
|
+
let basketId = undefined;
|
|
699
|
+
try{
|
|
700
|
+
basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken);
|
|
701
|
+
} catch(e) {
|
|
702
|
+
console.error(e);
|
|
703
|
+
return {type: 'error', msg: 'Basket not found'};
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
axios.post('api/basket/update-extraInfo', {
|
|
707
|
+
basketId,
|
|
708
|
+
basketProductId,
|
|
709
|
+
extraInfo
|
|
710
|
+
}).then(res =>
|
|
711
|
+
updateBasket({commit}, basketId, res)
|
|
712
|
+
).catch(
|
|
713
|
+
commonErrorCallback()
|
|
714
|
+
);
|
|
696
715
|
}
|
|
697
716
|
}
|
|
698
717
|
export default {
|
package/src/modules/product.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import Vue from 'vue';
|
|
3
|
-
import {
|
|
3
|
+
import {commonErrorCallback, calculateBasketIdParameter, restaurantId, updateBasket} from '../common';
|
|
4
4
|
|
|
5
5
|
const state = () => ({
|
|
6
6
|
selectedTime: null,
|
|
@@ -257,51 +257,24 @@ const actions = {
|
|
|
257
257
|
commonErrorCallback()
|
|
258
258
|
);
|
|
259
259
|
},
|
|
260
|
-
getBasket({ commit, rootState }
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
basketId
|
|
264
|
-
}
|
|
260
|
+
getBasket({ commit, rootState }) {
|
|
261
|
+
let basketId = undefined;
|
|
262
|
+
try{
|
|
263
|
+
basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken);
|
|
264
|
+
} catch(e) {
|
|
265
|
+
console.error(e);
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
265
268
|
|
|
266
269
|
commit('startFetchingBasket');
|
|
267
270
|
return axios.get('api/basket', {
|
|
268
271
|
params: {
|
|
269
|
-
|
|
270
|
-
restaurantId
|
|
271
|
-
}
|
|
272
|
-
}).then(res => {
|
|
273
|
-
const basketInfo = res.data.data;
|
|
274
|
-
commit('setBasketInfo', basketInfo);
|
|
275
|
-
|
|
276
|
-
// TODO: why two separate states use same value?
|
|
277
|
-
commit('SetSubtotalPrice', basketInfo.totalPrice);
|
|
278
|
-
commit('SetTotalPrice', basketInfo.totalPrice);
|
|
279
|
-
|
|
280
|
-
commit('SetShoppingCart', basketInfo.products);
|
|
281
|
-
commit('setDeliveryTime', basketInfo.deliveryTime);
|
|
282
|
-
commit('setVoucherCode', basketInfo.voucher_code);
|
|
283
|
-
commit('setVoucherValue', basketInfo.voucherValue);
|
|
284
|
-
commit('setTotalWithDiscount', basketInfo.totalWithDiscount);
|
|
285
|
-
commit('setDelivertType', basketInfo.deliveryType);
|
|
286
|
-
commit('setPostalCode', basketInfo.postalCode);
|
|
287
|
-
commit('setTip', basketInfo.tip);
|
|
288
|
-
commit('setshippingPrice', basketInfo.shipping_price);
|
|
289
|
-
|
|
290
|
-
//TODO: This condition is always true.
|
|
291
|
-
if (basketInfo.id != basketId) {
|
|
292
|
-
const index = basket.indexOf(basket.find((basket) => basket.restaurantId == restaurantId));
|
|
293
|
-
if (index > -1) {
|
|
294
|
-
basket.splice(index, 1);
|
|
295
|
-
}
|
|
296
|
-
basket.push({
|
|
297
|
-
restaurantId: restaurantId,
|
|
298
|
-
basketId: basketInfo.id,
|
|
299
|
-
});
|
|
300
|
-
localStorage.setItem("basket", JSON.stringify(basket));
|
|
272
|
+
basketId,
|
|
273
|
+
restaurantId
|
|
301
274
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
275
|
+
}).then(res =>
|
|
276
|
+
updateBasket({commit}, basketId, res)
|
|
277
|
+
).catch(error => {
|
|
305
278
|
console.error(error);
|
|
306
279
|
return false;
|
|
307
280
|
}).finally(() => {
|