orderiom-api-package 0.2.56 → 0.2.58

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orderiom-api-package",
3
- "version": "0.2.56",
3
+ "version": "0.2.58",
4
4
  "description": "This package will install all necessary API calls for every orderiom restaurant",
5
5
  "main": "index.js",
6
6
  "scripts": {
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, isOutsideProduct}){
42
+ const basketInfo = res.data.data;
43
+ commit(`${isOutsideProduct ? 'product/' : ''}setBasketInfo`, basketInfo);
44
+
45
+ // TODO: why two separate states use same value?
46
+ commit(`${isOutsideProduct ? 'product/' : ''}SetSubtotalPrice`, basketInfo.totalPrice);
47
+ commit(`${isOutsideProduct ? 'product/' : ''}SetTotalPrice`, basketInfo.totalPrice);
48
+
49
+ commit(`${isOutsideProduct ? 'product/' : ''}SetShoppingCart`, basketInfo.products);
50
+ commit(`${isOutsideProduct ? 'product/' : ''}setDeliveryTime`, basketInfo.deliveryTime);
51
+ commit(`${isOutsideProduct ? 'product/' : ''}setVoucherCode`, basketInfo.voucher_code);
52
+ commit(`${isOutsideProduct ? 'product/' : ''}setVoucherValue`, basketInfo.voucherValue);
53
+ commit(`${isOutsideProduct ? 'product/' : ''}setTotalWithDiscount`, basketInfo.totalWithDiscount);
54
+ commit(`${isOutsideProduct ? 'product/' : ''}setDelivertType`, basketInfo.deliveryType);
55
+ commit(`${isOutsideProduct ? 'product/' : ''}setPostalCode`, basketInfo.postalCode);
56
+ commit(`${isOutsideProduct ? 'product/' : ''}setTip`, basketInfo.tip);
57
+ commit(`${isOutsideProduct ? '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(`${isOutsideProduct ? 'product/' : ''}basketLoadedOnce`);
71
+ return true;
39
72
  }
@@ -1,5 +1,5 @@
1
1
  import axios from "axios";
2
- import { commonErrorCallback, calculateBasketIdParameter, restaurantId } from '../common';
2
+ import {commonErrorCallback, calculateBasketIdParameter, restaurantId, updateBasket} from '../common';
3
3
 
4
4
  const state = () => ({
5
5
  productOrder: null,
@@ -693,6 +693,24 @@ const actions = {
693
693
  }).catch(
694
694
  commonErrorCallback()
695
695
  );
696
+ },
697
+ editCartProductExtraInfo({rootState, commit}, data){
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
+ ...data
709
+ }).then(res =>
710
+ updateBasket({commit, basketId, res, isOutsideProduct: true})
711
+ ).catch(
712
+ commonErrorCallback()
713
+ );
696
714
  }
697
715
  }
698
716
  export default {
@@ -1,6 +1,6 @@
1
1
  import axios from "axios";
2
2
  import Vue from 'vue';
3
- import { commonErrorCallback, calculateBasketIdParameter, restaurantId } from '../common';
3
+ import {commonErrorCallback, calculateBasketIdParameter, restaurantId, updateBasket} from '../common';
4
4
 
5
5
  const state = () => ({
6
6
  selectedTime: null,
@@ -272,38 +272,9 @@ const actions = {
272
272
  basketId,
273
273
  restaurantId
274
274
  }
275
- }).then(res => {
276
- const basketInfo = res.data.data;
277
- commit('setBasketInfo', basketInfo);
278
-
279
- // TODO: why two separate states use same value?
280
- commit('SetSubtotalPrice', basketInfo.totalPrice);
281
- commit('SetTotalPrice', basketInfo.totalPrice);
282
-
283
- commit('SetShoppingCart', basketInfo.products);
284
- commit('setDeliveryTime', basketInfo.deliveryTime);
285
- commit('setVoucherCode', basketInfo.voucher_code);
286
- commit('setVoucherValue', basketInfo.voucherValue);
287
- commit('setTotalWithDiscount', basketInfo.totalWithDiscount);
288
- commit('setDelivertType', basketInfo.deliveryType);
289
- commit('setPostalCode', basketInfo.postalCode);
290
- commit('setTip', basketInfo.tip);
291
- commit('setshippingPrice', basketInfo.shipping_price);
292
-
293
- if (parseInt(basketInfo.id) !== parseInt(basketId)) {
294
- const baskets = JSON.parse(localStorage.getItem('basket'));
295
- const basketIndex = baskets.findIndex(basket => parseInt(basket.restaurantId) === restaurantId);
296
- if (basketIndex > -1) baskets.splice(basketIndex, 1);
297
- baskets.push({
298
- restaurantId,
299
- basketId: basketInfo.id,
300
- });
301
- localStorage.setItem('basket', JSON.stringify(baskets));
302
- }
303
-
304
- commit('basketLoadedOnce');
305
- return true;
306
- }).catch(error => {
275
+ }).then(res =>
276
+ updateBasket({commit, basketId, res, isOutsideProduct: false})
277
+ ).catch(error => {
307
278
  console.error(error);
308
279
  return false;
309
280
  }).finally(() => {