ok
This commit is contained in:
@@ -140,6 +140,37 @@ export default function Invoice({ table, sendParam, deviceType, socket }) {
|
||||
console.log(table);
|
||||
}, [table]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log(localStorage.getItem('cart'))
|
||||
console.log(cartItems)
|
||||
|
||||
// Parse the local storage cart
|
||||
const localStorageCart = JSON.parse(localStorage.getItem('cart'));
|
||||
|
||||
// Create a set of itemIds from the local storage cart for quick lookup
|
||||
const localStorageItemIds = new Set(localStorageCart[0].items.map(item => item.itemId));
|
||||
|
||||
// Filter out items from cartItems that do not exist in the local storage cart
|
||||
const updatedCartItems = cartItems.map(itemType => ({
|
||||
...itemType,
|
||||
itemList: itemType.itemList.filter(item => localStorageItemIds.has(item.itemId))
|
||||
}));
|
||||
|
||||
setCartItems(updatedCartItems);
|
||||
|
||||
|
||||
const totalPrice = updatedCartItems.reduce((total, itemType) => {
|
||||
return (
|
||||
total +
|
||||
itemType.itemList.reduce((subtotal, item) => {
|
||||
return subtotal + item.qty * item.price;
|
||||
}, 0)
|
||||
);
|
||||
}, 0);
|
||||
setTotalPrice(totalPrice);
|
||||
}, [localStorage.getItem('cart')]);
|
||||
|
||||
|
||||
const handleOrderTypeChange = (event) => {
|
||||
setOrderType(event.target.value);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user