DSatishchandra commited on
Commit
793139a
·
verified ·
1 Parent(s): 9be918b

Update templates/menu.html

Browse files
Files changed (1) hide show
  1. templates/menu.html +16 -13
templates/menu.html CHANGED
@@ -553,19 +553,22 @@ function addToCartFromModal() {
553
  body: JSON.stringify(cartPayload)
554
  })
555
  .then(response => response.json())
556
- .then(data => {
557
- if (data.success) {
558
- updateCartUI(data.cart); // Update the cart icon or cart details on the same page
559
- alert('Item added to cart!');
560
- } else {
561
- alert(data.error || 'Failed to add item to cart.');
562
- }
563
- })
564
- .catch(err => {
565
- console.error('Error adding item to cart:', err);
566
- alert('An error occurred while adding the item to the cart.');
567
- });
568
-
 
 
 
569
  function updateCartUI(cart) {
570
  if (!Array.isArray(cart)) {
571
  console.error('Invalid cart data:', cart);
 
553
  body: JSON.stringify(cartPayload)
554
  })
555
  .then(response => response.json())
556
+ .then(data => {
557
+ if (data.success) {
558
+ alert('Item added to cart successfully!');
559
+ updateCartUI(data.cart); // Update cart UI after adding an item
560
+ const modal = document.getElementById('itemModal');
561
+ const modalInstance = bootstrap.Modal.getInstance(modal);
562
+ modalInstance.hide();
563
+ } else {
564
+ alert(data.error || 'Failed to add item to cart.');
565
+ }
566
+ })
567
+ .catch(err => {
568
+ console.error('Error adding item to cart:', err);
569
+ alert('An error occurred while adding the item to the cart.');
570
+ });
571
+ }
572
  function updateCartUI(cart) {
573
  if (!Array.isArray(cart)) {
574
  console.error('Invalid cart data:', cart);