Spaces:
Runtime error
Runtime error
Update templates/menu.html
Browse files- templates/menu.html +57 -49
templates/menu.html
CHANGED
@@ -506,56 +506,64 @@
|
|
506 |
|
507 |
|
508 |
function addToCartFromModal() {
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
|
|
|
|
558 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
559 |
// Function to round reward points to a single digit
|
560 |
function roundRewardPoints() {
|
561 |
let rewardPointsElement = document.getElementById('reward-points');
|
|
|
506 |
|
507 |
|
508 |
function addToCartFromModal() {
|
509 |
+
const itemName = document.getElementById('modal-name').innerText;
|
510 |
+
const itemPrice = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
|
511 |
+
const itemImage = document.getElementById('modal-img').src;
|
512 |
+
const modalSectionEl = document.getElementById('modal-section');
|
513 |
+
const section = modalSectionEl.getAttribute('data-section');
|
514 |
+
const selectedCategory = modalSectionEl.getAttribute('data-category');
|
515 |
+
|
516 |
+
// Collect selected add-ons
|
517 |
+
const selectedAddOns = Array.from(
|
518 |
+
document.querySelectorAll('#addons-list input[type="checkbox"]:checked')
|
519 |
+
).map(addon => ({
|
520 |
+
name: addon.getAttribute('data-name'),
|
521 |
+
price: parseFloat(addon.getAttribute('data-price'))
|
522 |
+
}));
|
523 |
+
|
524 |
+
const instructions = document.getElementById('modal-instructions').value;
|
525 |
+
|
526 |
+
// If necessary information is missing, alert the user
|
527 |
+
if (!itemName || !itemPrice) {
|
528 |
+
alert('Failed to add item to cart. Please try again.');
|
529 |
+
return;
|
530 |
+
}
|
531 |
+
|
532 |
+
// Prepare data for the cart
|
533 |
+
const cartPayload = {
|
534 |
+
itemName: itemName,
|
535 |
+
itemPrice: itemPrice,
|
536 |
+
itemImage: itemImage,
|
537 |
+
section: section,
|
538 |
+
category: selectedCategory,
|
539 |
+
addons: selectedAddOns,
|
540 |
+
instructions: instructions
|
541 |
+
};
|
542 |
+
|
543 |
+
// Send the cart data to the server
|
544 |
+
fetch('/cart/add', {
|
545 |
+
method: 'POST',
|
546 |
+
headers: {
|
547 |
+
'Content-Type': 'application/json',
|
548 |
+
},
|
549 |
+
body: JSON.stringify(cartPayload)
|
550 |
+
})
|
551 |
+
.then(response => response.json())
|
552 |
+
.then(data => {
|
553 |
+
if (data.success) {
|
554 |
+
alert('Item added to cart successfully!');
|
555 |
+
const modal = document.getElementById('itemModal');
|
556 |
+
const modalInstance = bootstrap.Modal.getInstance(modal);
|
557 |
+
modalInstance.hide();
|
558 |
+
} else {
|
559 |
+
alert(data.error || 'Failed to add item to cart.');
|
560 |
}
|
561 |
+
})
|
562 |
+
.catch(err => {
|
563 |
+
console.error('Error adding item to cart:', err);
|
564 |
+
alert('An error occurred while adding the item to the cart.');
|
565 |
+
});
|
566 |
+
}
|
567 |
// Function to round reward points to a single digit
|
568 |
function roundRewardPoints() {
|
569 |
let rewardPointsElement = document.getElementById('reward-points');
|