Spaces:
Runtime error
Runtime error
Update templates/menu.html
Browse files- templates/menu.html +51 -9
templates/menu.html
CHANGED
@@ -1002,6 +1002,10 @@ function addSoftDrinkToCart(name, price, image, section, category, index) {
|
|
1002 |
alert('An error occurred while adding the Soft Drink to the cart.');
|
1003 |
});
|
1004 |
}
|
|
|
|
|
|
|
|
|
1005 |
// Function to increase quantity
|
1006 |
function increaseQuantity(name, index) {
|
1007 |
let quantityElement = document.getElementById(`quantity-${index}`);
|
@@ -1026,16 +1030,54 @@ function decreaseQuantity(name, index) {
|
|
1026 |
}
|
1027 |
}
|
1028 |
// Existing updateCartUI function (unchanged, but included for reference)
|
1029 |
-
function updateCartUI(cart) {
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1038 |
}
|
|
|
1039 |
|
1040 |
</script>
|
1041 |
|
|
|
1002 |
alert('An error occurred while adding the Soft Drink to the cart.');
|
1003 |
});
|
1004 |
}
|
1005 |
+
|
1006 |
+
|
1007 |
+
|
1008 |
+
|
1009 |
// Function to increase quantity
|
1010 |
function increaseQuantity(name, index) {
|
1011 |
let quantityElement = document.getElementById(`quantity-${index}`);
|
|
|
1030 |
}
|
1031 |
}
|
1032 |
// Existing updateCartUI function (unchanged, but included for reference)
|
1033 |
+
// function updateCartUI(cart) {
|
1034 |
+
// if (!Array.isArray(cart)) {
|
1035 |
+
// console.error('Invalid cart data:', cart);
|
1036 |
+
// return;
|
1037 |
+
// }
|
1038 |
+
// const cartIcon = document.getElementById('cart-icon');
|
1039 |
+
// if (cartIcon) {
|
1040 |
+
// cartIcon.innerText = cart.length; // Update cart icon if it exists
|
1041 |
+
// }
|
1042 |
+
// }
|
1043 |
+
function updateCartUI(cartData) {
|
1044 |
+
// Assuming cartData is an array of cart items
|
1045 |
+
const cartItemsContainer = document.getElementById('cart-items'); // The container where cart items are listed
|
1046 |
+
const cartTotalPrice = document.getElementById('cart-total-price'); // The element where total price is displayed
|
1047 |
+
const cartTotalQuantity = document.getElementById('cart-total-quantity'); // The element where total quantity is displayed
|
1048 |
+
|
1049 |
+
// Clear current cart items in the UI
|
1050 |
+
cartItemsContainer.innerHTML = '';
|
1051 |
+
|
1052 |
+
let totalPrice = 0;
|
1053 |
+
let totalQuantity = 0;
|
1054 |
+
|
1055 |
+
// Loop through cartData to update UI
|
1056 |
+
cartData.forEach(item => {
|
1057 |
+
const itemRow = document.createElement('div');
|
1058 |
+
itemRow.classList.add('cart-item');
|
1059 |
+
|
1060 |
+
itemRow.innerHTML = `
|
1061 |
+
<div class="cart-item-details">
|
1062 |
+
<img src="${item.itemImage}" alt="${item.itemName}" class="cart-item-img">
|
1063 |
+
<span class="cart-item-name">${item.itemName}</span>
|
1064 |
+
<span class="cart-item-price">$${item.itemPrice.toFixed(2)}</span>
|
1065 |
+
<span class="cart-item-quantity">Qty: ${item.quantity}</span>
|
1066 |
+
</div>
|
1067 |
+
`;
|
1068 |
+
|
1069 |
+
cartItemsContainer.appendChild(itemRow);
|
1070 |
+
|
1071 |
+
// Update the total price and quantity
|
1072 |
+
totalPrice += item.itemPrice * item.quantity;
|
1073 |
+
totalQuantity += item.quantity;
|
1074 |
+
});
|
1075 |
+
|
1076 |
+
// Update the total price and quantity in the UI
|
1077 |
+
cartTotalPrice.innerText = `Total: $${totalPrice.toFixed(2)}`;
|
1078 |
+
cartTotalQuantity.innerText = `Items: ${totalQuantity}`;
|
1079 |
}
|
1080 |
+
|
1081 |
|
1082 |
</script>
|
1083 |
|