Spaces:
Runtime error
Runtime error
Update templates/menu.html
Browse files- templates/menu.html +32 -127
templates/menu.html
CHANGED
|
@@ -1147,47 +1147,6 @@ document.addEventListener('DOMContentLoaded', function () {
|
|
| 1147 |
ft Drink added to cart successfully!');
|
| 1148 |
|
| 1149 |
// subbu###################
|
| 1150 |
-
// function addSoftDrinkToCart(name, price, image, section, category, index) {
|
| 1151 |
-
// const itemPrice = parseFloat(price);
|
| 1152 |
-
// const quantity = 1; // Default quantity
|
| 1153 |
-
|
| 1154 |
-
// const cartPayload = {
|
| 1155 |
-
// itemName: name,
|
| 1156 |
-
// itemPrice: itemPrice,
|
| 1157 |
-
// itemImage: image || '/static/placeholder.jpg',
|
| 1158 |
-
// section: section,
|
| 1159 |
-
// category: category,
|
| 1160 |
-
// addons: [], // No add-ons for Soft Drinks
|
| 1161 |
-
// instructions: '', // No instructions for Soft Drinks
|
| 1162 |
-
// quantity: quantity
|
| 1163 |
-
// };
|
| 1164 |
-
|
| 1165 |
-
// fetch('/cart/add', {
|
| 1166 |
-
// method: 'POST',
|
| 1167 |
-
// headers: {
|
| 1168 |
-
// 'Content-Type': 'application/json',
|
| 1169 |
-
// },
|
| 1170 |
-
// body: JSON.stringify(cartPayload)
|
| 1171 |
-
// })
|
| 1172 |
-
// .then(response => response.json())
|
| 1173 |
-
// .then(data => {
|
| 1174 |
-
// if (data.success) {
|
| 1175 |
-
// // Hide the ADD button and show quantity controls
|
| 1176 |
-
// document.getElementById(`add-btn-${index}`).style.display = 'none';
|
| 1177 |
-
// document.getElementById(`quantity-control-${index}`).style.display = 'flex';
|
| 1178 |
-
// updateCartQuantity(data.cart);
|
| 1179 |
-
// alert('Soft Drink added to cart successfully!');
|
| 1180 |
-
// } else {
|
| 1181 |
-
// alert(data.error || 'Failed to add Soft Drink to cart.');
|
| 1182 |
-
// }
|
| 1183 |
-
// })
|
| 1184 |
-
// .catch(err => {
|
| 1185 |
-
// console.error('Error adding Soft Drink to cart:', err);
|
| 1186 |
-
// alert('An error occurred while adding the Soft Drink to the cart.');
|
| 1187 |
-
// });
|
| 1188 |
-
// }
|
| 1189 |
-
|
| 1190 |
-
// Add Soft Drink to Cart with a default quantity of 1
|
| 1191 |
function addSoftDrinkToCart(name, price, image, section, category, index) {
|
| 1192 |
const itemPrice = parseFloat(price);
|
| 1193 |
const quantity = 1; // Default quantity
|
|
@@ -1203,7 +1162,6 @@ function addSoftDrinkToCart(name, price, image, section, category, index) {
|
|
| 1203 |
quantity: quantity
|
| 1204 |
};
|
| 1205 |
|
| 1206 |
-
// Add item to cart for the first time
|
| 1207 |
fetch('/cart/add', {
|
| 1208 |
method: 'POST',
|
| 1209 |
headers: {
|
|
@@ -1217,7 +1175,7 @@ function addSoftDrinkToCart(name, price, image, section, category, index) {
|
|
| 1217 |
// Hide the ADD button and show quantity controls
|
| 1218 |
document.getElementById(`add-btn-${index}`).style.display = 'none';
|
| 1219 |
document.getElementById(`quantity-control-${index}`).style.display = 'flex';
|
| 1220 |
-
updateCartQuantity(data.cart);
|
| 1221 |
alert('Soft Drink added to cart successfully!');
|
| 1222 |
} else {
|
| 1223 |
alert(data.error || 'Failed to add Soft Drink to cart.');
|
|
@@ -1228,50 +1186,29 @@ function addSoftDrinkToCart(name, price, image, section, category, index) {
|
|
| 1228 |
alert('An error occurred while adding the Soft Drink to the cart.');
|
| 1229 |
});
|
| 1230 |
}
|
|
|
|
|
|
|
|
|
|
| 1231 |
// subbu###################
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
-
|
| 1238 |
-
// let quantityElement = document.getElementById(`quantity-${index}`);
|
| 1239 |
-
// let currentQuantity = parseInt(quantityElement.innerText);
|
| 1240 |
-
// currentQuantity++; // Increase the quantity by 1
|
| 1241 |
-
// quantityElement.innerText = currentQuantity;
|
| 1242 |
-
|
| 1243 |
-
// // Update cart immediately
|
| 1244 |
-
// updateCartQuantity(name, currentQuantity);
|
| 1245 |
-
// }
|
| 1246 |
-
function increaseQuantity(name, index) {
|
| 1247 |
let quantityElement = document.getElementById(`quantity-${index}`);
|
| 1248 |
let currentQuantity = parseInt(quantityElement.innerText);
|
| 1249 |
currentQuantity++; // Increase the quantity by 1
|
| 1250 |
quantityElement.innerText = currentQuantity;
|
| 1251 |
|
| 1252 |
-
// Update cart immediately
|
| 1253 |
updateCartQuantity(name, currentQuantity);
|
| 1254 |
}
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
-
|
| 1259 |
-
|
| 1260 |
-
// let currentQuantity = parseInt(quantityElement.innerText);
|
| 1261 |
-
|
| 1262 |
-
// if (currentQuantity > 1) {
|
| 1263 |
-
// currentQuantity--;
|
| 1264 |
-
// quantityElement.innerText = currentQuantity;
|
| 1265 |
-
// // Update cart immediately
|
| 1266 |
-
// updateCartQuantity(name, currentQuantity);
|
| 1267 |
-
// } else {
|
| 1268 |
-
// // Remove from cart if quantity is 1 and show the "Add" button
|
| 1269 |
-
// removeFromCart(name, index);
|
| 1270 |
-
// document.getElementById(`add-btn-${index}`).style.display = 'block'; // Show ADD button
|
| 1271 |
-
// document.getElementById(`quantity-control-${index}`).style.display = 'none'; // Hide quantity controls
|
| 1272 |
-
// }
|
| 1273 |
-
// }
|
| 1274 |
-
function decreaseQuantity(name, index) {
|
| 1275 |
let quantityElement = document.getElementById(`quantity-${index}`);
|
| 1276 |
let currentQuantity = parseInt(quantityElement.innerText);
|
| 1277 |
|
|
@@ -1281,78 +1218,46 @@ function addSoftDrinkToCart(name, price, image, section, category, index) {
|
|
| 1281 |
// Update cart immediately
|
| 1282 |
updateCartQuantity(name, currentQuantity);
|
| 1283 |
} else {
|
| 1284 |
-
// Remove from cart if quantity is 1
|
| 1285 |
removeFromCart(name, index);
|
| 1286 |
document.getElementById(`add-btn-${index}`).style.display = 'block'; // Show ADD button
|
| 1287 |
document.getElementById(`quantity-control-${index}`).style.display = 'none'; // Hide quantity controls
|
| 1288 |
}
|
| 1289 |
}
|
|
|
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
-
|
| 1294 |
-
|
| 1295 |
-
// if (!Array.isArray(cart)) {
|
| 1296 |
-
// console.error('Invalid cart data:', cart);
|
| 1297 |
-
// return;
|
| 1298 |
-
// }
|
| 1299 |
-
// const cartIcon = document.getElementById('cart-icon');
|
| 1300 |
-
// cartIcon.innerText = cart.length; // Assuming cart is an array of items
|
| 1301 |
-
// }
|
| 1302 |
-
function updateCartQuantity(name, newQuantity) {
|
| 1303 |
-
const customerEmail = "user@example.com"; // Get the logged-in user's email
|
| 1304 |
-
fetch(`/cart/update_quantity`, {
|
| 1305 |
-
method: 'POST',
|
| 1306 |
-
headers: { 'Content-Type': 'application/json' },
|
| 1307 |
-
body: JSON.stringify({
|
| 1308 |
-
email: customerEmail,
|
| 1309 |
-
item_name: name.trim(),
|
| 1310 |
-
quantity: newQuantity
|
| 1311 |
-
})
|
| 1312 |
-
})
|
| 1313 |
-
.then(response => response.json())
|
| 1314 |
-
.then(data => {
|
| 1315 |
-
if (data.success) {
|
| 1316 |
-
alert("Item quantity updated successfully.");
|
| 1317 |
-
updateCartDisplay(data.cart); // Update cart UI
|
| 1318 |
-
} else {
|
| 1319 |
-
alert(data.error || "Failed to update item quantity.");
|
| 1320 |
-
}
|
| 1321 |
-
})
|
| 1322 |
-
.catch(err => console.error("Error updating item quantity:", err));
|
| 1323 |
-
}
|
| 1324 |
-
|
| 1325 |
-
// function updateCartDisplay(cart) {
|
| 1326 |
-
// if (!Array.isArray(cart)) {
|
| 1327 |
-
// console.error('Invalid cart data:', cart);
|
| 1328 |
-
// return;
|
| 1329 |
-
// }
|
| 1330 |
-
// // Optional: Update quantity on the cart page
|
| 1331 |
-
// const cartCountElement = document.getElementById('cart-count');
|
| 1332 |
-
// cartCountElement.innerText = cart.reduce((total, item)=> total+item.quantity,0); // Update cart item count //Sum of all quantities
|
| 1333 |
-
|
| 1334 |
-
// // Optionally, show a small success notification that the item was added
|
| 1335 |
-
// const successNotification = document.createElement('div');
|
| 1336 |
-
// successNotification.classList.add('success-notification');
|
| 1337 |
-
// successNotification.innerText = 'Item added to cart!';
|
| 1338 |
-
// document.body.appendChild(successNotification);
|
| 1339 |
-
// setTimeout(() => {
|
| 1340 |
-
// successNotification.remove(); // Remove success notification after a few seconds
|
| 1341 |
-
// }, 2000);
|
| 1342 |
-
// }
|
| 1343 |
-
function updateCartDisplay(cart) {
|
| 1344 |
if (!Array.isArray(cart)) {
|
| 1345 |
console.error('Invalid cart data:', cart);
|
| 1346 |
return;
|
| 1347 |
}
|
| 1348 |
-
|
| 1349 |
const cartIcon = document.getElementById('cart-icon');
|
| 1350 |
-
cartIcon.innerText = cart.length;
|
|
|
|
| 1351 |
|
| 1352 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1353 |
const cartCountElement = document.getElementById('cart-count');
|
| 1354 |
-
cartCountElement.innerText = cart.reduce((total, item)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1355 |
}
|
|
|
|
| 1356 |
|
| 1357 |
|
| 1358 |
</script>
|
|
|
|
| 1147 |
ft Drink added to cart successfully!');
|
| 1148 |
|
| 1149 |
// subbu###################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1150 |
function addSoftDrinkToCart(name, price, image, section, category, index) {
|
| 1151 |
const itemPrice = parseFloat(price);
|
| 1152 |
const quantity = 1; // Default quantity
|
|
|
|
| 1162 |
quantity: quantity
|
| 1163 |
};
|
| 1164 |
|
|
|
|
| 1165 |
fetch('/cart/add', {
|
| 1166 |
method: 'POST',
|
| 1167 |
headers: {
|
|
|
|
| 1175 |
// Hide the ADD button and show quantity controls
|
| 1176 |
document.getElementById(`add-btn-${index}`).style.display = 'none';
|
| 1177 |
document.getElementById(`quantity-control-${index}`).style.display = 'flex';
|
| 1178 |
+
updateCartQuantity(data.cart);
|
| 1179 |
alert('Soft Drink added to cart successfully!');
|
| 1180 |
} else {
|
| 1181 |
alert(data.error || 'Failed to add Soft Drink to cart.');
|
|
|
|
| 1186 |
alert('An error occurred while adding the Soft Drink to the cart.');
|
| 1187 |
});
|
| 1188 |
}
|
| 1189 |
+
|
| 1190 |
+
|
| 1191 |
+
|
| 1192 |
// subbu###################
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
+
function increaseQuantity(name, index) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1199 |
let quantityElement = document.getElementById(`quantity-${index}`);
|
| 1200 |
let currentQuantity = parseInt(quantityElement.innerText);
|
| 1201 |
currentQuantity++; // Increase the quantity by 1
|
| 1202 |
quantityElement.innerText = currentQuantity;
|
| 1203 |
|
| 1204 |
+
// Update cart immediately
|
| 1205 |
updateCartQuantity(name, currentQuantity);
|
| 1206 |
}
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
+
|
| 1211 |
+
function decreaseQuantity(name, index) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1212 |
let quantityElement = document.getElementById(`quantity-${index}`);
|
| 1213 |
let currentQuantity = parseInt(quantityElement.innerText);
|
| 1214 |
|
|
|
|
| 1218 |
// Update cart immediately
|
| 1219 |
updateCartQuantity(name, currentQuantity);
|
| 1220 |
} else {
|
| 1221 |
+
// Remove from cart if quantity is 1 and show the "Add" button
|
| 1222 |
removeFromCart(name, index);
|
| 1223 |
document.getElementById(`add-btn-${index}`).style.display = 'block'; // Show ADD button
|
| 1224 |
document.getElementById(`quantity-control-${index}`).style.display = 'none'; // Hide quantity controls
|
| 1225 |
}
|
| 1226 |
}
|
| 1227 |
+
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
+
Function to update cart quantity
|
| 1232 |
+
function updateCartQuantity(cart) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1233 |
if (!Array.isArray(cart)) {
|
| 1234 |
console.error('Invalid cart data:', cart);
|
| 1235 |
return;
|
| 1236 |
}
|
|
|
|
| 1237 |
const cartIcon = document.getElementById('cart-icon');
|
| 1238 |
+
cartIcon.innerText = cart.length; // Assuming cart is an array of items
|
| 1239 |
+
}
|
| 1240 |
|
| 1241 |
+
|
| 1242 |
+
function updateCartDisplay(cart) {
|
| 1243 |
+
if (!Array.isArray(cart)) {
|
| 1244 |
+
console.error('Invalid cart data:', cart);
|
| 1245 |
+
return;
|
| 1246 |
+
}
|
| 1247 |
+
// Optional: Update quantity on the cart page
|
| 1248 |
const cartCountElement = document.getElementById('cart-count');
|
| 1249 |
+
cartCountElement.innerText = cart.reduce((total, item)=> total+item.quantity,0); // Update cart item count //Sum of all quantities
|
| 1250 |
+
|
| 1251 |
+
// Optionally, show a small success notification that the item was added
|
| 1252 |
+
const successNotification = document.createElement('div');
|
| 1253 |
+
successNotification.classList.add('success-notification');
|
| 1254 |
+
successNotification.innerText = 'Item added to cart!';
|
| 1255 |
+
document.body.appendChild(successNotification);
|
| 1256 |
+
setTimeout(() => {
|
| 1257 |
+
successNotification.remove(); // Remove success notification after a few seconds
|
| 1258 |
+
}, 2000);
|
| 1259 |
}
|
| 1260 |
+
|
| 1261 |
|
| 1262 |
|
| 1263 |
</script>
|