Subbu1304 commited on
Commit
aefa70a
·
verified ·
1 Parent(s): 364a449

Update templates/menu.html

Browse files
Files changed (1) hide show
  1. templates/menu.html +36 -36
templates/menu.html CHANGED
@@ -964,43 +964,43 @@ document.addEventListener('DOMContentLoaded', function () {
964
 
965
  // Function to add Soft Drink to cart directly
966
  function addSoftDrinkToCart(name, price, image, section, category, index) {
967
- // // const itemPrice = parseFloat(price);
968
- // // const quantity = 1; // Default quantity
969
-
970
- // // const cartPayload = {
971
- // // itemName: name,
972
- // // itemPrice: itemPrice,
973
- // // itemImage: image || '/static/placeholder.jpg',
974
- // // section: section,
975
- // // category: category,
976
- // // addons: [], // No add-ons for Soft Drinks
977
- // // instructions: '', // No instructions for Soft Drinks
978
- // quantity: quantity
979
- // };
980
 
981
- // fetch('/cart/add', {
982
- // method: 'POST',
983
- // headers: {
984
- // 'Content-Type': 'application/json',
985
- // },
986
- // body: JSON.stringify(cartPayload)
987
- // })
988
- // .then(response => response.json())
989
- // .then(data => {
990
- // if (data.success) {
991
- // // Hide the ADD button and show quantity controls
992
- // document.getElementById(`add-btn-${index}`).style.display = 'none';
993
- // document.getElementById(`quantity-control-${index}`).style.display = 'flex';
994
- // updateCartUI(data.cart);
995
- // alert('Soft Drink added to cart successfully!');
996
- // } else {
997
- // alert(data.error || 'Failed to add Soft Drink to cart.');
998
- // }
999
- // })
1000
- // .catch(err => {
1001
- // console.error('Error adding Soft Drink to cart:', err);
1002
- // alert('An error occurred while adding the Soft Drink to the cart.');
1003
- // });
 
 
 
 
 
 
 
 
 
 
 
1004
  }
1005
  // function addSoftDrinkToCart(name, price, image, section, category, index) {
1006
  // const itemPrice = parseFloat(price);
 
964
 
965
  // Function to add Soft Drink to cart directly
966
  function addSoftDrinkToCart(name, price, image, section, category, index) {
967
+ const itemPrice = parseFloat(price);
968
+ const quantity = 1; // Default quantity
 
 
 
 
 
 
 
 
 
 
 
969
 
970
+ const cartPayload = {
971
+ itemName: name,
972
+ itemPrice: itemPrice,
973
+ itemImage: image || '/static/placeholder.jpg',
974
+ section: section,
975
+ category: category,
976
+ addons: [], // No add-ons for Soft Drinks
977
+ instructions: '', // No instructions for Soft Drinks
978
+ quantity: quantity
979
+ };
980
+
981
+ fetch('/cart/add', {
982
+ method: 'POST',
983
+ headers: {
984
+ 'Content-Type': 'application/json',
985
+ },
986
+ body: JSON.stringify(cartPayload)
987
+ })
988
+ .then(response => response.json())
989
+ .then(data => {
990
+ if (data.success) {
991
+ // Hide the ADD button and show quantity controls
992
+ document.getElementById(`add-btn-${index}`).style.display = 'none';
993
+ document.getElementById(`quantity-control-${index}`).style.display = 'flex';
994
+ updateCartUI(data.cart);
995
+ alert('Soft Drink added to cart successfully!');
996
+ } else {
997
+ alert(data.error || 'Failed to add Soft Drink to cart.');
998
+ }
999
+ })
1000
+ .catch(err => {
1001
+ console.error('Error adding Soft Drink to cart:', err);
1002
+ alert('An error occurred while adding the Soft Drink to the cart.');
1003
+ });
1004
  }
1005
  // function addSoftDrinkToCart(name, price, image, section, category, index) {
1006
  // const itemPrice = parseFloat(price);