orderiom-api-package
Advanced tools
Comparing version 0.2.54 to 0.2.55
{ | ||
"name": "orderiom-api-package", | ||
"version": "0.2.54", | ||
"version": "0.2.55", | ||
"description": "This package will install all necessary API calls for every orderiom restaurant", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -56,2 +56,3 @@ import axios from "axios"; | ||
...item, | ||
extra_info: item.extra_info ? JSON.parse(item.extra_info) : item.extra_info, | ||
deleting: false, | ||
@@ -260,3 +261,3 @@ changingQuantity: false, | ||
}, | ||
getBasket({ commit, rootState }, restaurantId) { | ||
getBasket({ commit, rootState }, customRestaurantId = undefined) { | ||
const basket = JSON.parse(localStorage.getItem("basket")); | ||
@@ -268,49 +269,45 @@ const basketId = !rootState.orderiomApiPackage.auth.privateToken ? { | ||
commit('startFetchingBasket'); | ||
return axios | ||
.get('api/basket', { params: { ...basketId, restaurantId } }).then(res => { | ||
const basketInfo = res.data.data; | ||
const id = res.data.data.id; | ||
const ShoppingCart = res.data.data.products; | ||
const SubtotalPrice = res.data.data.totalPrice; | ||
const deliveryTime = res.data.data.deliveryTime; | ||
const totalPrice = res.data.data.totalPrice; | ||
const voucherValue = res.data.data.voucherValue; | ||
const voucher_code = res.data.data.voucher_code; | ||
const totalWithDiscount = res.data.data.totalWithDiscount; | ||
const delivertYype = res.data.data.deliveryType; | ||
const postalCode = res.data.data.postalCode; | ||
const tip = res.data.data.tip; | ||
const shipping_price = res.data.data.shipping_price; | ||
commit('setBasketInfo', basketInfo) | ||
commit("SetSubtotalPrice", SubtotalPrice); | ||
commit("SetTotalPrice", totalPrice); | ||
commit("SetShoppingCart", ShoppingCart); | ||
commit("setDeliveryTime", deliveryTime); | ||
commit('setVoucherCode', voucher_code); | ||
commit('setVoucherValue', voucherValue); | ||
commit('setTotalWithDiscount', totalWithDiscount); | ||
commit('setDelivertType', delivertYype); | ||
commit('setPostalCode', postalCode); | ||
commit('setTip', tip); | ||
commit('setshippingPrice', shipping_price); | ||
if (id != basketId) { | ||
const index = basket.indexOf(basket.find((basket) => basket.restaurantId == restaurantId)); | ||
if (index > -1) { | ||
basket.splice(index, 1); | ||
} | ||
basket.push({ | ||
restaurantId: restaurantId, | ||
basketId: id, | ||
}); | ||
localStorage.setItem("basket", JSON.stringify(basket)); | ||
return axios.get('api/basket', { | ||
params: { | ||
...basketId, | ||
restaurantId: customRestaurantId || restaurantId | ||
} | ||
}).then(res => { | ||
const basketInfo = res.data.data; | ||
commit('setBasketInfo', basketInfo); | ||
// TODO: why two separate states use same value? | ||
commit('SetSubtotalPrice', basketInfo.totalPrice); | ||
commit('SetTotalPrice', basketInfo.totalPrice); | ||
commit('SetShoppingCart', basketInfo.products); | ||
commit('setDeliveryTime', basketInfo.deliveryTime); | ||
commit('setVoucherCode', basketInfo.voucher_code); | ||
commit('setVoucherValue', basketInfo.voucherValue); | ||
commit('setTotalWithDiscount', basketInfo.totalWithDiscount); | ||
commit('setDelivertType', basketInfo.deliveryType); | ||
commit('setPostalCode', basketInfo.postalCode); | ||
commit('setTip', basketInfo.tip); | ||
commit('setshippingPrice', basketInfo.shipping_price); | ||
//TODO: This condition is always true. | ||
if (basketInfo.id != basketId) { | ||
const index = basket.indexOf(basket.find((basket) => basket.restaurantId == restaurantId)); | ||
if (index > -1) { | ||
basket.splice(index, 1); | ||
} | ||
commit('basketLoadedOnce'); | ||
return true; | ||
}).catch(error => { | ||
console.error(error); | ||
return false; | ||
}).finally(() => { | ||
commit('finishFetchingBasket') | ||
}); | ||
basket.push({ | ||
restaurantId: restaurantId, | ||
basketId: basketInfo.id, | ||
}); | ||
localStorage.setItem("basket", JSON.stringify(basket)); | ||
} | ||
commit('basketLoadedOnce'); | ||
return true; | ||
}).catch(error => { | ||
console.error(error); | ||
return false; | ||
}).finally(() => { | ||
commit('finishFetchingBasket') | ||
}); | ||
}, | ||
@@ -317,0 +314,0 @@ getAttributeItems({ commit }, data) { |
90516
2171