Subbu1304 commited on
Commit
bf14c60
·
verified ·
1 Parent(s): 7364297

Update templates/menu.html

Browse files
Files changed (1) hide show
  1. templates/menu.html +35 -2
templates/menu.html CHANGED
@@ -554,7 +554,7 @@ form-check-input addon-option{
554
  <p class="card-text">${{ item.Price__c }}</p>
555
  </div>
556
  <div>
557
- <button class="btn btn-primary">Add</button>
558
  </div>
559
  </div>
560
  </div>
@@ -863,8 +863,41 @@ document.addEventListener('DOMContentLoaded', function () {
863
  });
864
  });
865
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
866
 
867
-
868
  </script>
869
 
870
  <!-- Bootstrap JS -->
 
554
  <p class="card-text">${{ item.Price__c }}</p>
555
  </div>
556
  <div>
557
+ <button class="btn btn-primary"onclick="addToCart()">Add</button>
558
  </div>
559
  </div>
560
  </div>
 
863
  });
864
  });
865
 
866
+
867
+
868
+
869
+
870
+
871
+ // subbu
872
+
873
+
874
+
875
+
876
+
877
+
878
+ function addToCart(itemName, customerEmail) {
879
+ fetch(`/cart/add_item`, {
880
+ method: "POST",
881
+ headers: { "Content-Type": "application/json" },
882
+ body: JSON.stringify({
883
+ email: customerEmail,
884
+ item_name: itemName.trim(), //Ensure the item name is trimmed
885
+ quantity: 0 // DEFAULT QUANTITY PASSED HERE
886
+ })
887
+ })
888
+ .then(response => response.json())
889
+ .then(data => {
890
+ if (data.success) {
891
+ alert("Item added/updated successfully.");
892
+ location.reload(); // Reload the page to update the cart
893
+ } else {
894
+ alert(data.error || "Failed to add item to cart.");
895
+ }
896
+ })
897
+ .catch(err => console.error("Error adding item to cart:", err));
898
+ }
899
 
900
+ // subbu
901
  </script>
902
 
903
  <!-- Bootstrap JS -->