orderiom-api-package 0.2.54 → 0.2.56

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.54",
3
+ "version": "0.2.56",
4
4
  "description": "This package will install all necessary API calls for every orderiom restaurant",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -53,6 +53,7 @@ const mutations = {
53
53
  SetShoppingCart(state, products) {
54
54
  state.ShoppingCart = products.map(item => ({
55
55
  ...item,
56
+ extra_info: item.extra_info ? JSON.parse(item.extra_info) : item.extra_info,
56
57
  deleting: false,
57
58
  changingQuantity: false,
58
59
  }));
@@ -256,60 +257,58 @@ const actions = {
256
257
  commonErrorCallback()
257
258
  );
258
259
  },
259
- getBasket({ commit, rootState }, restaurantId) {
260
- const basket = JSON.parse(localStorage.getItem("basket"));
261
- const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
262
- basketId: basket.find((basket) => basket.restaurantId == restaurantId).basketId
263
- } : {}
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
+ }
264
268
 
265
269
  commit('startFetchingBasket');
266
- return axios
267
- .get('api/basket', { params: { ...basketId, restaurantId } }).then(res => {
268
- const basketInfo = res.data.data;
269
- const id = res.data.data.id;
270
- const ShoppingCart = res.data.data.products;
271
- const SubtotalPrice = res.data.data.totalPrice;
272
- const deliveryTime = res.data.data.deliveryTime;
273
- const totalPrice = res.data.data.totalPrice;
274
- const voucherValue = res.data.data.voucherValue;
275
- const voucher_code = res.data.data.voucher_code;
276
- const totalWithDiscount = res.data.data.totalWithDiscount;
277
- const delivertYype = res.data.data.deliveryType;
278
- const postalCode = res.data.data.postalCode;
279
- const tip = res.data.data.tip;
280
- const shipping_price = res.data.data.shipping_price;
281
- commit('setBasketInfo', basketInfo)
282
- commit("SetSubtotalPrice", SubtotalPrice);
283
- commit("SetTotalPrice", totalPrice);
284
- commit("SetShoppingCart", ShoppingCart);
285
- commit("setDeliveryTime", deliveryTime);
286
- commit('setVoucherCode', voucher_code);
287
- commit('setVoucherValue', voucherValue);
288
- commit('setTotalWithDiscount', totalWithDiscount);
289
- commit('setDelivertType', delivertYype);
290
- commit('setPostalCode', postalCode);
291
- commit('setTip', tip);
292
- commit('setshippingPrice', shipping_price);
293
- if (id != basketId) {
294
- const index = basket.indexOf(basket.find((basket) => basket.restaurantId == restaurantId));
295
- if (index > -1) {
296
- basket.splice(index, 1);
297
- }
298
- basket.push({
299
- restaurantId: restaurantId,
300
- basketId: id,
301
- });
302
- localStorage.setItem("basket", JSON.stringify(basket));
270
+ return axios.get('api/basket', {
271
+ params: {
272
+ basketId,
273
+ restaurantId
274
+ }
275
+ }).then(res => {
276
+ const basketInfo = res.data.data;
277
+ commit('setBasketInfo', basketInfo);
303
278
 
304
- }
305
- commit('basketLoadedOnce');
306
- return true;
307
- }).catch(error => {
308
- console.error(error);
309
- return false;
310
- }).finally(() => {
311
- commit('finishFetchingBasket')
312
- });
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 => {
307
+ console.error(error);
308
+ return false;
309
+ }).finally(() => {
310
+ commit('finishFetchingBasket')
311
+ });
313
312
  },
314
313
  getAttributeItems({ commit }, data) {
315
314
  return axios.get('api/restaurant/category-attributes-items', {