orderiom-api-package
Advanced tools
Comparing version 0.2.56 to 0.2.57
{ | ||
"name": "orderiom-api-package", | ||
"version": "0.2.56", | ||
"version": "0.2.57", | ||
"description": "This package will install all necessary API calls for every orderiom restaurant", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -39,2 +39,35 @@ export const restaurantId = parseInt(process.env.VUE_APP_RESTAURANT_ID) || null; | ||
return foundBasket.basketId; | ||
} | ||
export function updateBasket({commit}, basketId, res){ | ||
const basketInfo = res.data.data; | ||
commit('product/setBasketInfo', basketInfo); | ||
// TODO: why two separate states use same value? | ||
commit('product/SetSubtotalPrice', basketInfo.totalPrice); | ||
commit('product/SetTotalPrice', basketInfo.totalPrice); | ||
commit('product/SetShoppingCart', basketInfo.products); | ||
commit('product/setDeliveryTime', basketInfo.deliveryTime); | ||
commit('product/setVoucherCode', basketInfo.voucher_code); | ||
commit('product/setVoucherValue', basketInfo.voucherValue); | ||
commit('product/setTotalWithDiscount', basketInfo.totalWithDiscount); | ||
commit('product/setDelivertType', basketInfo.deliveryType); | ||
commit('product/setPostalCode', basketInfo.postalCode); | ||
commit('product/setTip', basketInfo.tip); | ||
commit('product/setshippingPrice', basketInfo.shipping_price); | ||
if (parseInt(basketInfo.id) !== parseInt(basketId)) { | ||
const baskets = JSON.parse(localStorage.getItem('basket')); | ||
const basketIndex = baskets.findIndex(basket => parseInt(basket.restaurantId) === restaurantId); | ||
if (basketIndex > -1) baskets.splice(basketIndex, 1); | ||
baskets.push({ | ||
restaurantId, | ||
basketId: basketInfo.id, | ||
}); | ||
localStorage.setItem('basket', JSON.stringify(baskets)); | ||
} | ||
commit('product/basketLoadedOnce'); | ||
return true; | ||
} |
import axios from "axios"; | ||
import { commonErrorCallback, calculateBasketIdParameter, restaurantId } from '../common'; | ||
import {commonErrorCallback, calculateBasketIdParameter, restaurantId, updateBasket} from '../common'; | ||
@@ -696,2 +696,21 @@ const state = () => ({ | ||
); | ||
}, | ||
editCartProductExtraInfo({rootState, commit}, {basketProductId, extraInfo}){ | ||
let basketId = undefined; | ||
try{ | ||
basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken); | ||
} catch(e) { | ||
console.error(e); | ||
return {type: 'error', msg: 'Basket not found'}; | ||
} | ||
axios.post('api/basket/update-extraInfo', { | ||
basketId, | ||
basketProductId, | ||
extraInfo | ||
}).then(res => | ||
updateBasket({commit}, basketId, res) | ||
).catch( | ||
commonErrorCallback() | ||
); | ||
} | ||
@@ -698,0 +717,0 @@ } |
import axios from "axios"; | ||
import Vue from 'vue'; | ||
import { commonErrorCallback, calculateBasketIdParameter, restaurantId } from '../common'; | ||
import {commonErrorCallback, calculateBasketIdParameter, restaurantId, updateBasket} from '../common'; | ||
@@ -275,34 +275,5 @@ const state = () => ({ | ||
} | ||
}).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); | ||
if (parseInt(basketInfo.id) !== parseInt(basketId)) { | ||
const baskets = JSON.parse(localStorage.getItem('basket')); | ||
const basketIndex = baskets.findIndex(basket => parseInt(basket.restaurantId) === restaurantId); | ||
if (basketIndex > -1) baskets.splice(basketIndex, 1); | ||
baskets.push({ | ||
restaurantId, | ||
basketId: basketInfo.id, | ||
}); | ||
localStorage.setItem('basket', JSON.stringify(baskets)); | ||
} | ||
commit('basketLoadedOnce'); | ||
return true; | ||
}).catch(error => { | ||
}).then(res => | ||
updateBasket({commit}, basketId, res) | ||
).catch(error => { | ||
console.error(error); | ||
@@ -309,0 +280,0 @@ return false; |
90979
2193