changes
This commit is contained in:
@@ -27,5 +27,10 @@ export default function useActiveCart({ carts, cartItems, customers }) {
|
||||
return activeCartItems.value?.reduce((prev, curr) => prev + curr.imei__variant__price, 0);
|
||||
});
|
||||
|
||||
return { activeCartId, activeCart, activeCartItems, customerIdsWithNoCart, subtotal };
|
||||
const invalidCartItems = ref([]);
|
||||
|
||||
watch(activeCartId, () => {
|
||||
invalidCartItems.value = [];
|
||||
});
|
||||
return { activeCartId, activeCart, activeCartItems, customerIdsWithNoCart, subtotal, invalidCartItems };
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export default function usePlaceOrder({
|
||||
activeCart,
|
||||
activeCartItems,
|
||||
invalidCartItems,
|
||||
orderInfo,
|
||||
fullAddress,
|
||||
subtotal,
|
||||
@@ -16,6 +17,22 @@ export default function usePlaceOrder({
|
||||
const payment_record = ref();
|
||||
const showVietQRModal = ref();
|
||||
|
||||
async function checkImeiAvai() {
|
||||
const imeisSold = await $getdata("IMEI_Sold");
|
||||
const invalidImeis = [];
|
||||
|
||||
for (const cartItem of activeCartItems.value) {
|
||||
if (imeisSold.find((sold) => sold.imei === cartItem.imei__imei)) {
|
||||
invalidImeis.push(cartItem);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
allAvailable: invalidImeis.length === 0,
|
||||
invalidImeis,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a record in `invoice` as `pending`
|
||||
*/
|
||||
@@ -193,6 +210,14 @@ export default function usePlaceOrder({
|
||||
}
|
||||
|
||||
async function placeOrder() {
|
||||
const { allAvailable, invalidImeis } = await checkImeiAvai();
|
||||
if (!allAvailable) {
|
||||
invalidCartItems.value = invalidImeis;
|
||||
console.error("IMEIs not available", invalidImeis);
|
||||
$snackbar("Một số IMEI đã được bán, vui lòng kiểm tra lại", "Error");
|
||||
return;
|
||||
}
|
||||
|
||||
await createOrder();
|
||||
|
||||
if (orderInfo.value.paymentMethod.code === "CASH") {
|
||||
|
||||
Reference in New Issue
Block a user