Spaces:
Runtime error
Runtime error
Update templates/menu.html
Browse files- templates/menu.html +151 -32
templates/menu.html
CHANGED
@@ -963,6 +963,46 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
963 |
});
|
964 |
|
965 |
// Function to add Soft Drink to cart directly
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
966 |
function addSoftDrinkToCart(name, price, image, section, category, index) {
|
967 |
const itemPrice = parseFloat(price);
|
968 |
const quantity = 1; // Default quantity
|
@@ -1004,9 +1044,20 @@ function addSoftDrinkToCart(name, price, image, section, category, index) {
|
|
1004 |
}
|
1005 |
|
1006 |
|
|
|
|
|
|
|
1007 |
|
1008 |
|
1009 |
// Function to increase quantity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1010 |
function increaseQuantity(name, index) {
|
1011 |
let quantityElement = document.getElementById(`quantity-${index}`);
|
1012 |
let currentQuantity = parseInt(quantityElement.innerText);
|
@@ -1016,7 +1067,38 @@ function increaseQuantity(name, index) {
|
|
1016 |
updateCartQuantity(name, currentQuantity);
|
1017 |
}
|
1018 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1019 |
// Function to decrease quantity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1020 |
function decreaseQuantity(name, index) {
|
1021 |
let quantityElement = document.getElementById(`quantity-${index}`);
|
1022 |
let currentQuantity = parseInt(quantityElement.innerText);
|
@@ -1027,8 +1109,16 @@ function decreaseQuantity(name, index) {
|
|
1027 |
} else {
|
1028 |
// Remove from cart and revert to ADD button
|
1029 |
removeFromCart(name, index);
|
|
|
|
|
1030 |
}
|
1031 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1032 |
// Existing updateCartUI function (unchanged, but included for reference)
|
1033 |
// function updateCartUI(cart) {
|
1034 |
// if (!Array.isArray(cart)) {
|
@@ -1040,42 +1130,71 @@ function decreaseQuantity(name, index) {
|
|
1040 |
// cartIcon.innerText = cart.length; // Update cart icon if it exists
|
1041 |
// }
|
1042 |
// }
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1068 |
|
1069 |
-
cartItemsContainer.appendChild(itemRow);
|
1070 |
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1074 |
});
|
|
|
1075 |
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
}
|
1080 |
|
1081 |
|
|
|
963 |
});
|
964 |
|
965 |
// Function to add Soft Drink to cart directly
|
966 |
+
// function addSoftDrinkToCart(name, price, image, section, category, index) {
|
967 |
+
// const itemPrice = parseFloat(price);
|
968 |
+
// const quantity = 1; // Default quantity
|
969 |
+
|
970 |
+
// const cartPayload = {
|
971 |
+
// itemName: name,
|
972 |
+
// itemPrice: itemPrice,
|
973 |
+
// itemImage: image || '/static/placeholder.jpg',
|
974 |
+
// section: section,
|
975 |
+
// category: category,
|
976 |
+
// addons: [], // No add-ons for Soft Drinks
|
977 |
+
// instructions: '', // No instructions for Soft Drinks
|
978 |
+
// quantity: quantity
|
979 |
+
// };
|
980 |
+
|
981 |
+
// fetch('/cart/add', {
|
982 |
+
// method: 'POST',
|
983 |
+
// headers: {
|
984 |
+
// 'Content-Type': 'application/json',
|
985 |
+
// },
|
986 |
+
// body: JSON.stringify(cartPayload)
|
987 |
+
// })
|
988 |
+
// .then(response => response.json())
|
989 |
+
// .then(data => {
|
990 |
+
// if (data.success) {
|
991 |
+
// // Hide the ADD button and show quantity controls
|
992 |
+
// document.getElementById(`add-btn-${index}`).style.display = 'none';
|
993 |
+
// document.getElementById(`quantity-control-${index}`).style.display = 'flex';
|
994 |
+
// updateCartUI(data.cart);
|
995 |
+
// alert('Soft Drink added to cart successfully!');
|
996 |
+
// } else {
|
997 |
+
// alert(data.error || 'Failed to add Soft Drink to cart.');
|
998 |
+
// }
|
999 |
+
// })
|
1000 |
+
// .catch(err => {
|
1001 |
+
// console.error('Error adding Soft Drink to cart:', err);
|
1002 |
+
// alert('An error occurred while adding the Soft Drink to the cart.');
|
1003 |
+
// });
|
1004 |
+
// }
|
1005 |
+
// subbu###################
|
1006 |
function addSoftDrinkToCart(name, price, image, section, category, index) {
|
1007 |
const itemPrice = parseFloat(price);
|
1008 |
const quantity = 1; // Default quantity
|
|
|
1044 |
}
|
1045 |
|
1046 |
|
1047 |
+
// subbu###################
|
1048 |
+
|
1049 |
+
|
1050 |
|
1051 |
|
1052 |
// Function to increase quantity
|
1053 |
+
// function increaseQuantity(name, index) {
|
1054 |
+
// let quantityElement = document.getElementById(`quantity-${index}`);
|
1055 |
+
// let currentQuantity = parseInt(quantityElement.innerText);
|
1056 |
+
// currentQuantity++;
|
1057 |
+
// quantityElement.innerText = currentQuantity;
|
1058 |
+
|
1059 |
+
// updateCartQuantity(name, currentQuantity);
|
1060 |
+
// }
|
1061 |
function increaseQuantity(name, index) {
|
1062 |
let quantityElement = document.getElementById(`quantity-${index}`);
|
1063 |
let currentQuantity = parseInt(quantityElement.innerText);
|
|
|
1067 |
updateCartQuantity(name, currentQuantity);
|
1068 |
}
|
1069 |
|
1070 |
+
|
1071 |
+
|
1072 |
+
|
1073 |
+
|
1074 |
+
|
1075 |
+
|
1076 |
+
|
1077 |
+
|
1078 |
+
|
1079 |
+
|
1080 |
+
|
1081 |
+
|
1082 |
+
|
1083 |
+
|
1084 |
+
|
1085 |
+
|
1086 |
+
|
1087 |
// Function to decrease quantity
|
1088 |
+
// function decreaseQuantity(name, index) {
|
1089 |
+
// let quantityElement = document.getElementById(`quantity-${index}`);
|
1090 |
+
// let currentQuantity = parseInt(quantityElement.innerText);
|
1091 |
+
// if (currentQuantity > 1) {
|
1092 |
+
// currentQuantity--;
|
1093 |
+
// quantityElement.innerText = currentQuantity;
|
1094 |
+
// updateCartQuantity(name, currentQuantity);
|
1095 |
+
// } else {
|
1096 |
+
// // Remove from cart and revert to ADD button
|
1097 |
+
// removeFromCart(name, index);
|
1098 |
+
// }
|
1099 |
+
// }
|
1100 |
+
|
1101 |
+
|
1102 |
function decreaseQuantity(name, index) {
|
1103 |
let quantityElement = document.getElementById(`quantity-${index}`);
|
1104 |
let currentQuantity = parseInt(quantityElement.innerText);
|
|
|
1109 |
} else {
|
1110 |
// Remove from cart and revert to ADD button
|
1111 |
removeFromCart(name, index);
|
1112 |
+
document.getElementById(`add-btn-${index}`).style.display = 'block'; // Show the ADD button again
|
1113 |
+
document.getElementById(`quantity-control-${index}`).style.display = 'none'; // Hide the quantity controls
|
1114 |
}
|
1115 |
}
|
1116 |
+
|
1117 |
+
|
1118 |
+
|
1119 |
+
|
1120 |
+
|
1121 |
+
|
1122 |
// Existing updateCartUI function (unchanged, but included for reference)
|
1123 |
// function updateCartUI(cart) {
|
1124 |
// if (!Array.isArray(cart)) {
|
|
|
1130 |
// cartIcon.innerText = cart.length; // Update cart icon if it exists
|
1131 |
// }
|
1132 |
// }
|
1133 |
+
// function updateCartUI(cartData) {
|
1134 |
+
// // Assuming cartData is an array of cart items
|
1135 |
+
// const cartItemsContainer = document.getElementById('cart-items'); // The container where cart items are listed
|
1136 |
+
// const cartTotalPrice = document.getElementById('cart-total-price'); // The element where total price is displayed
|
1137 |
+
// const cartTotalQuantity = document.getElementById('cart-total-quantity'); // The element where total quantity is displayed
|
1138 |
+
|
1139 |
+
// // Clear current cart items in the UI
|
1140 |
+
// cartItemsContainer.innerHTML = '';
|
1141 |
+
|
1142 |
+
// let totalPrice = 0;
|
1143 |
+
// let totalQuantity = 0;
|
1144 |
+
|
1145 |
+
// // Loop through cartData to update UI
|
1146 |
+
// cartData.forEach(item => {
|
1147 |
+
// const itemRow = document.createElement('div');
|
1148 |
+
// itemRow.classList.add('cart-item');
|
1149 |
+
|
1150 |
+
// itemRow.innerHTML = `
|
1151 |
+
// <div class="cart-item-details">
|
1152 |
+
// <img src="${item.itemImage}" alt="${item.itemName}" class="cart-item-img">
|
1153 |
+
// <span class="cart-item-name">${item.itemName}</span>
|
1154 |
+
// <span class="cart-item-price">$${item.itemPrice.toFixed(2)}</span>
|
1155 |
+
// <span class="cart-item-quantity">Qty: ${item.quantity}</span>
|
1156 |
+
// </div>
|
1157 |
+
// `;
|
1158 |
+
|
1159 |
+
// cartItemsContainer.appendChild(itemRow);
|
1160 |
+
|
1161 |
+
// // Update the total price and quantity
|
1162 |
+
// totalPrice += item.itemPrice * item.quantity;
|
1163 |
+
// totalQuantity += item.quantity;
|
1164 |
+
// });
|
1165 |
+
|
1166 |
+
// // Update the total price and quantity in the UI
|
1167 |
+
// cartTotalPrice.innerText = `Total: $${totalPrice.toFixed(2)}`;
|
1168 |
+
// cartTotalQuantity.innerText = `Items: ${totalQuantity}`;
|
1169 |
+
// }
|
1170 |
|
|
|
1171 |
|
1172 |
+
// Function to update cart quantity
|
1173 |
+
function updateCartQuantity(name, quantity) {
|
1174 |
+
fetch('/cart/update', {
|
1175 |
+
method: 'POST',
|
1176 |
+
headers: {
|
1177 |
+
'Content-Type': 'application/json',
|
1178 |
+
},
|
1179 |
+
body: JSON.stringify({ itemName: name, quantity: quantity })
|
1180 |
+
})
|
1181 |
+
.then(response => response.json())
|
1182 |
+
.then(data => {
|
1183 |
+
if (data.success) {
|
1184 |
+
updateCartUI(data.cart);
|
1185 |
+
} else {
|
1186 |
+
alert(data.error || 'Failed to update cart quantity.');
|
1187 |
+
}
|
1188 |
+
})
|
1189 |
+
.catch(err => {
|
1190 |
+
console.error('Error updating cart quantity:', err);
|
1191 |
+
alert('An error occurred while updating the cart quantity.');
|
1192 |
});
|
1193 |
+
}
|
1194 |
|
1195 |
+
// Function to update the cart UI after changes
|
1196 |
+
function updateCartUI(cart) {
|
1197 |
+
// Your logic to update the cart UI (display total, items, etc.)
|
1198 |
}
|
1199 |
|
1200 |
|