orderiom-api-package 0.2.54 → 0.2.55

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.55",
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,56 @@ const actions = {
256
257
  commonErrorCallback()
257
258
  );
258
259
  },
259
- getBasket({ commit, rootState }, restaurantId) {
260
+ getBasket({ commit, rootState }, customRestaurantId = undefined) {
260
261
  const basket = JSON.parse(localStorage.getItem("basket"));
261
262
  const basketId = !rootState.orderiomApiPackage.auth.privateToken ? {
262
263
  basketId: basket.find((basket) => basket.restaurantId == restaurantId).basketId
263
264
  } : {}
264
265
 
265
266
  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));
267
+ return axios.get('api/basket', {
268
+ params: {
269
+ ...basketId,
270
+ restaurantId: customRestaurantId || restaurantId
271
+ }
272
+ }).then(res => {
273
+ const basketInfo = res.data.data;
274
+ commit('setBasketInfo', basketInfo);
303
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);
304
295
  }
305
- commit('basketLoadedOnce');
306
- return true;
307
- }).catch(error => {
308
- console.error(error);
309
- return false;
310
- }).finally(() => {
311
- commit('finishFetchingBasket')
312
- });
296
+ basket.push({
297
+ restaurantId: restaurantId,
298
+ basketId: basketInfo.id,
299
+ });
300
+ localStorage.setItem("basket", JSON.stringify(basket));
301
+ }
302
+ commit('basketLoadedOnce');
303
+ return true;
304
+ }).catch(error => {
305
+ console.error(error);
306
+ return false;
307
+ }).finally(() => {
308
+ commit('finishFetchingBasket')
309
+ });
313
310
  },
314
311
  getAttributeItems({ commit }, data) {
315
312
  return axios.get('api/restaurant/category-attributes-items', {