Spaces:
Sleeping
Sleeping
Update templates/menu.html
Browse files- templates/menu.html +26 -2
templates/menu.html
CHANGED
@@ -504,8 +504,7 @@
|
|
504 |
});
|
505 |
}
|
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;
|
@@ -552,6 +551,7 @@
|
|
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();
|
@@ -564,6 +564,30 @@
|
|
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');
|
|
|
504 |
});
|
505 |
}
|
506 |
|
507 |
+
function addToCartFromModal() {
|
|
|
508 |
const itemName = document.getElementById('modal-name').innerText;
|
509 |
const itemPrice = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
|
510 |
const itemImage = document.getElementById('modal-img').src;
|
|
|
551 |
.then(data => {
|
552 |
if (data.success) {
|
553 |
alert('Item added to cart successfully!');
|
554 |
+
updateCartUI(data.cart); // Update cart UI after adding an item
|
555 |
const modal = document.getElementById('itemModal');
|
556 |
const modalInstance = bootstrap.Modal.getInstance(modal);
|
557 |
modalInstance.hide();
|
|
|
564 |
alert('An error occurred while adding the item to the cart.');
|
565 |
});
|
566 |
}
|
567 |
+
|
568 |
+
function updateCartUI(cart) {
|
569 |
+
// This function should update the cart UI with the new items in the cart
|
570 |
+
// You could update a cart icon or a cart section with the updated number of items
|
571 |
+
const cartIcon = document.getElementById('cart-icon');
|
572 |
+
cartIcon.innerText = cart.length; // Assuming cart is an array of items
|
573 |
+
}
|
574 |
+
|
575 |
+
function updateCartDisplay(cart) {
|
576 |
+
// Assuming you have an element with id 'cart-count' to display the number of items in the cart
|
577 |
+
const cartCountElement = document.getElementById('cart-count');
|
578 |
+
cartCountElement.innerText = cart.length; // Update cart item count
|
579 |
+
|
580 |
+
// Optionally, show a small success notification that the item was added
|
581 |
+
const successNotification = document.createElement('div');
|
582 |
+
successNotification.classList.add('success-notification');
|
583 |
+
successNotification.innerText = 'Item added to cart!';
|
584 |
+
document.body.appendChild(successNotification);
|
585 |
+
|
586 |
+
setTimeout(() => {
|
587 |
+
successNotification.remove(); // Remove success notification after a few seconds
|
588 |
+
}, 2000);
|
589 |
+
}
|
590 |
+
|
591 |
// Function to round reward points to a single digit
|
592 |
function roundRewardPoints() {
|
593 |
let rewardPointsElement = document.getElementById('reward-points');
|