Spaces:
Sleeping
Sleeping
Update templates/menu.html
Browse files- templates/menu.html +16 -15
templates/menu.html
CHANGED
@@ -506,19 +506,24 @@
|
|
506 |
|
507 |
function addToCartFromModal() {
|
508 |
const itemName = document.getElementById('modal-name').innerText;
|
509 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
510 |
const itemImage = document.getElementById('modal-img').src;
|
511 |
console.log(itemName, itemPrice, itemImage); // Log values for debugging
|
512 |
const modalSectionEl = document.getElementById('modal-section');
|
513 |
const section = modalSectionEl.getAttribute('data-section');
|
514 |
const selectedCategory = modalSectionEl.getAttribute('data-category');
|
515 |
-
|
516 |
if (!itemName || !itemPrice || !section) {
|
517 |
console.error('Missing data for cart item:', { itemName, itemPrice, section });
|
518 |
return;
|
519 |
}
|
520 |
|
521 |
-
|
522 |
// Collect selected add-ons
|
523 |
let selectedAddOns = Array.from(
|
524 |
document.querySelectorAll('#addons-list input[type="checkbox"]:checked')
|
@@ -526,15 +531,8 @@ function addToCartFromModal() {
|
|
526 |
name: addon.getAttribute('data-name') || 'Default Name', //Fallback Name
|
527 |
price: parseFloat(addon.getAttribute('data-price') || 0)
|
528 |
}));
|
529 |
-
|
530 |
const instructions = document.getElementById('modal-instructions').value;
|
531 |
|
532 |
-
// If necessary information is missing, alert the user
|
533 |
-
if (!itemName || !itemPrice) {
|
534 |
-
alert('Failed to add item to cart. Please try again.');
|
535 |
-
return;
|
536 |
-
}
|
537 |
-
|
538 |
// Prepare data for the cart
|
539 |
const cartPayload = {
|
540 |
itemName: itemName,
|
@@ -573,23 +571,26 @@ function addToCartFromModal() {
|
|
573 |
}
|
574 |
|
575 |
function updateCartUI(cart) {
|
576 |
-
|
577 |
-
|
|
|
|
|
578 |
const cartIcon = document.getElementById('cart-icon');
|
579 |
cartIcon.innerText = cart.length; // Assuming cart is an array of items
|
580 |
}
|
581 |
|
582 |
function updateCartDisplay(cart) {
|
583 |
-
|
|
|
|
|
|
|
584 |
const cartCountElement = document.getElementById('cart-count');
|
585 |
cartCountElement.innerText = cart.length; // Update cart item count
|
586 |
-
|
587 |
// Optionally, show a small success notification that the item was added
|
588 |
const successNotification = document.createElement('div');
|
589 |
successNotification.classList.add('success-notification');
|
590 |
successNotification.innerText = 'Item added to cart!';
|
591 |
document.body.appendChild(successNotification);
|
592 |
-
|
593 |
setTimeout(() => {
|
594 |
successNotification.remove(); // Remove success notification after a few seconds
|
595 |
}, 2000);
|
|
|
506 |
|
507 |
function addToCartFromModal() {
|
508 |
const itemName = document.getElementById('modal-name').innerText;
|
509 |
+
let itemPrice = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
|
510 |
+
|
511 |
+
// Validate item price
|
512 |
+
if (isNaN(itemPrice)) {
|
513 |
+
alert('Invalid price for the item. Please check the item details.');
|
514 |
+
return;
|
515 |
+
}
|
516 |
+
|
517 |
const itemImage = document.getElementById('modal-img').src;
|
518 |
console.log(itemName, itemPrice, itemImage); // Log values for debugging
|
519 |
const modalSectionEl = document.getElementById('modal-section');
|
520 |
const section = modalSectionEl.getAttribute('data-section');
|
521 |
const selectedCategory = modalSectionEl.getAttribute('data-category');
|
|
|
522 |
if (!itemName || !itemPrice || !section) {
|
523 |
console.error('Missing data for cart item:', { itemName, itemPrice, section });
|
524 |
return;
|
525 |
}
|
526 |
|
|
|
527 |
// Collect selected add-ons
|
528 |
let selectedAddOns = Array.from(
|
529 |
document.querySelectorAll('#addons-list input[type="checkbox"]:checked')
|
|
|
531 |
name: addon.getAttribute('data-name') || 'Default Name', //Fallback Name
|
532 |
price: parseFloat(addon.getAttribute('data-price') || 0)
|
533 |
}));
|
|
|
534 |
const instructions = document.getElementById('modal-instructions').value;
|
535 |
|
|
|
|
|
|
|
|
|
|
|
|
|
536 |
// Prepare data for the cart
|
537 |
const cartPayload = {
|
538 |
itemName: itemName,
|
|
|
571 |
}
|
572 |
|
573 |
function updateCartUI(cart) {
|
574 |
+
if (!Array.isArray(cart)) {
|
575 |
+
console.error('Invalid cart data:', cart);
|
576 |
+
return;
|
577 |
+
}
|
578 |
const cartIcon = document.getElementById('cart-icon');
|
579 |
cartIcon.innerText = cart.length; // Assuming cart is an array of items
|
580 |
}
|
581 |
|
582 |
function updateCartDisplay(cart) {
|
583 |
+
if (!Array.isArray(cart)) {
|
584 |
+
console.error('Invalid cart data:', cart);
|
585 |
+
return;
|
586 |
+
}
|
587 |
const cartCountElement = document.getElementById('cart-count');
|
588 |
cartCountElement.innerText = cart.length; // Update cart item count
|
|
|
589 |
// Optionally, show a small success notification that the item was added
|
590 |
const successNotification = document.createElement('div');
|
591 |
successNotification.classList.add('success-notification');
|
592 |
successNotification.innerText = 'Item added to cart!';
|
593 |
document.body.appendChild(successNotification);
|
|
|
594 |
setTimeout(() => {
|
595 |
successNotification.remove(); // Remove success notification after a few seconds
|
596 |
}, 2000);
|