ok
This commit is contained in:
@@ -18,7 +18,7 @@ export const getItemsByCafeId = (cafeId) => {
|
||||
};
|
||||
|
||||
// Update quantity in localStorage for a specific cafeId and itemId
|
||||
export const updateItemQtyInCart = (cafeId, itemId, qty) => {
|
||||
export const updateItemQtyInCart = (cafeId, itemId, qty, price) => {
|
||||
let cart = JSON.parse(getLocalStorage('cart')) || [];
|
||||
const cafeIndex = cart.findIndex(cafeItem => cafeItem.cafeId === cafeId);
|
||||
|
||||
@@ -27,14 +27,15 @@ export const updateItemQtyInCart = (cafeId, itemId, qty) => {
|
||||
if (itemIndex > -1) {
|
||||
if (qty > 0) {
|
||||
cart[cafeIndex].items[itemIndex].qty = qty; // Update qty if item exists
|
||||
cart[cafeIndex].items[itemIndex].price = price; // Update qty if item exists
|
||||
} else {
|
||||
cart[cafeIndex].items.splice(itemIndex, 1); // Remove item if qty is 0
|
||||
}
|
||||
} else if (qty > 0) {
|
||||
cart[cafeIndex].items.push({ itemId, qty }); // Add new item
|
||||
cart[cafeIndex].items.push({ itemId, qty, price }); // Add new item
|
||||
}
|
||||
} else if (qty > 0) {
|
||||
cart.push({ cafeId, items: [{ itemId, qty }] }); // Add new cafeId and item
|
||||
cart.push({ cafeId, items: [{ itemId, qty, price }] }); // Add new cafeId and item
|
||||
}
|
||||
|
||||
updateLocalStorage('cart', JSON.stringify(cart));
|
||||
|
||||
Reference in New Issue
Block a user