lokeshloki143 commited on
Commit
0ea0767
·
verified ·
1 Parent(s): 149904f

Update templates/cart.html

Browse files
Files changed (1) hide show
  1. templates/cart.html +99 -48
templates/cart.html CHANGED
@@ -388,6 +388,7 @@
388
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
389
  border: 2px solid #fdf4e3;
390
  position: relative;
 
391
  }
392
  .menu-item img {
393
  width: 50px;
@@ -395,29 +396,36 @@
395
  object-fit: cover;
396
  border-radius: 5px;
397
  margin-right: 10px;
 
398
  }
399
  .menu-item:hover img {
400
  transform: scale(1.05);
401
  }
402
  .menu-item-details {
403
  flex-grow: 1;
 
 
 
 
404
  }
405
  .menu-item-details small {
406
  display: block;
407
  color: #666;
 
408
  }
409
  .quantity-selector {
410
- display: flex;
411
  align-items: center;
412
  }
413
  .quantity-selector button {
414
- width: 24px;
415
- height: 24px;
416
  border: none;
417
  background-color: #f0f0f0;
418
- font-size: 0.8rem;
419
  font-weight: bold;
420
  cursor: pointer;
 
421
  }
422
  .quantity-selector input {
423
  width: 40px;
@@ -426,6 +434,7 @@
426
  background-color: #f8f9fa;
427
  font-size: 1rem;
428
  margin: 0 5px;
 
429
  }
430
  .customization-section {
431
  display: none;
@@ -439,6 +448,8 @@
439
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
440
  z-index: 10;
441
  border: 2px solid #fdf4e3;
 
 
442
  }
443
  .customization-section.show {
444
  display: block;
@@ -450,6 +461,7 @@
450
  .customization-section label {
451
  display: block;
452
  margin-bottom: 5px;
 
453
  }
454
  .customization-section textarea {
455
  width: 100%;
@@ -458,11 +470,12 @@
458
  padding: 5px;
459
  border: 1px solid #ccc;
460
  border-radius: 5px;
 
461
  }
462
  .customization-actions {
463
  display: flex;
464
  justify-content: space-between;
465
- margin-top: 10px;
466
  }
467
  .customization-actions button {
468
  padding: 8px;
@@ -471,14 +484,14 @@
471
  cursor: pointer;
472
  width: 48%;
473
  text-align: center;
 
 
474
  }
475
  .add-to-cart-btn {
476
  background-color: #A52A2A;
477
- color: #fff;
478
  }
479
  .cancel-customization-btn {
480
  background-color: #6c757d;
481
- color: #fff;
482
  }
483
  .bill-item {
484
  display: flex;
@@ -666,13 +679,28 @@
666
  let currentCart = null;
667
  let menuItems = [];
668
  let selectedItem = null;
 
669
 
670
- // Static list of add-ons (replace with dynamic fetch if available)
671
- const availableAddOns = [
672
- { name: "Extra Raita ($2.00)", price: 2.00 },
673
- { name: "Extra Gravy ($3.00)", price: 3.00 },
674
- { name: "Extra Salad ($1.50)", price: 1.50 }
675
- ];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
676
 
677
  function updateQuantity(action, itemName, customerEmail) {
678
  let quantityInput = document.querySelector(`input[data-item-name="${itemName}"]`);
@@ -743,24 +771,27 @@
743
  if (selectedCoupon === "" || selectedCoupon === "None" || selectedCoupon === "Null") {
744
  selectedCoupon = null;
745
  }
746
- fetch('/cart/checkout', {
747
- method: 'POST',
748
- headers: { 'Content-Type': 'application/json' },
749
- body: JSON.stringify({ selectedCoupon: selectedCoupon })
750
- })
751
- .then(response => response.json())
752
- .then(data => {
753
- if (data.success) {
754
- currentCart = data.cart;
755
- menuItems = data.menu_items;
756
- displayAnythingElse();
757
- } else {
758
- alert(data.error || data.message);
759
- }
760
- })
761
- .catch(err => {
762
- console.error('Error during checkout:', err);
763
- alert('An error occurred. Please try again.');
 
 
 
764
  });
765
  }
766
 
@@ -778,21 +809,15 @@
778
  <small>$${item.Price__c.toFixed(2)}</small>
779
  </div>
780
  <button class="add-back-button" onclick="showQuantitySelector('${item.Name}', ${item.Price__c}, '${item.Image1__c}', this)">+</button>
781
- <div class="quantity-selector" style="display: none;">
782
  <button onclick="updateMenuItemQuantity('${item.Name}', 'decrease')">-</button>
783
  <input type="text" value="1" readonly data-item-name="${item.Name}">
784
  <button onclick="updateMenuItemQuantity('${item.Name}', 'increase')">+</button>
785
  </div>
786
  <div class="customization-section" data-item-name="${item.Name}">
787
  <h4>Customize ${item.Name}</h4>
788
- <div>
789
- <strong>Add-Ons</strong>
790
- ${availableAddOns.map(addon => `
791
- <label>
792
- <input type="checkbox" value="${addon.name}" data-price="${addon.price}">
793
- ${addon.name}
794
- </label>
795
- `).join('')}
796
  </div>
797
  <div>
798
  <strong>Special Instructions</strong>
@@ -805,6 +830,17 @@
805
  </div>
806
  `;
807
  menuItemsContainer.appendChild(itemElement);
 
 
 
 
 
 
 
 
 
 
 
808
  });
809
  document.getElementById('anythingElseModal').style.display = 'flex';
810
  }
@@ -813,20 +849,24 @@
813
  // Hide all quantity selectors and customization sections
814
  document.querySelectorAll('.quantity-selector').forEach(selector => {
815
  selector.style.display = 'none';
 
816
  });
817
  document.querySelectorAll('.customization-section').forEach(section => {
818
  section.classList.remove('show');
 
 
 
 
819
  });
820
  document.querySelectorAll('.add-back-button').forEach(btn => {
821
  btn.style.display = 'inline-block';
822
  });
823
 
824
- // Show quantity selector for the clicked item
825
  const quantitySelector = buttonElement.nextElementSibling;
826
  quantitySelector.style.display = 'flex';
827
  buttonElement.style.display = 'none';
828
 
829
- // Show customization section
830
  const customizationSection = quantitySelector.nextElementSibling;
831
  customizationSection.classList.add('show');
832
 
@@ -834,18 +874,21 @@
834
  }
835
 
836
  function updateMenuItemQuantity(itemName, action) {
837
- const quantityInput = document.querySelector(`.quantity-selector input[data-item-name="${itemName}"]`);
838
  let quantity = parseInt(quantityInput.value);
839
  if (action === 'increase') {
840
  quantity++;
841
  } else if (action === 'decrease' && quantity > 1) {
842
  quantity--;
843
  }
 
 
 
844
  quantityInput.value = quantity;
845
  }
846
 
847
  function cancelCustomization(itemName) {
848
- const quantitySelector = document.querySelector(`.quantity-selector input[data-item-name="${itemName}"]`).parentElement;
849
  const customizationSection = quantitySelector.nextElementSibling;
850
  const addButton = quantitySelector.previousElementSibling;
851
 
@@ -864,8 +907,12 @@
864
  }
865
 
866
  function addToCartWithCustomizations(itemName, itemPrice, itemImage) {
867
- const quantityInput = document.querySelector(`.quantity-selector input[data-item-name="${itemName}"]`);
868
- const quantity = parseInt(quantityInput.value);
 
 
 
 
869
  const customizationSection = document.querySelector(`.customization-section[data-item-name="${itemName}"]`);
870
  const addOns = Array.from(customizationSection.querySelectorAll('input[type="checkbox"]:checked')).map(checkbox => checkbox.value);
871
  const instructions = customizationSection.querySelector('textarea').value.trim();
@@ -895,7 +942,10 @@
895
  alert('Error adding item to cart: ' + data.error);
896
  }
897
  })
898
- .catch(err => console.error('Error adding item:', err));
 
 
 
899
  }
900
 
901
  function closeAnythingElseModal() {
@@ -995,7 +1045,8 @@
995
  item_image: itemImage,
996
  addons: [],
997
  instructions: "",
998
- customer_email: customerEmail
 
999
  };
1000
  fetch('/cart/add_suggestion_to_cart', {
1001
  method: 'POST',
 
388
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
389
  border: 2px solid #fdf4e3;
390
  position: relative;
391
+ min-height: 70px;
392
  }
393
  .menu-item img {
394
  width: 50px;
 
396
  object-fit: cover;
397
  border-radius: 5px;
398
  margin-right: 10px;
399
+ border: 1px solid #ffcc80;
400
  }
401
  .menu-item:hover img {
402
  transform: scale(1.05);
403
  }
404
  .menu-item-details {
405
  flex-grow: 1;
406
+ font-size: 0.9rem;
407
+ }
408
+ .menu-item-details strong {
409
+ font-size: 1rem;
410
  }
411
  .menu-item-details small {
412
  display: block;
413
  color: #666;
414
+ font-size: 0.8rem;
415
  }
416
  .quantity-selector {
417
+ display: none;
418
  align-items: center;
419
  }
420
  .quantity-selector button {
421
+ width: 28px;
422
+ height: 28px;
423
  border: none;
424
  background-color: #f0f0f0;
425
+ font-size: 1rem;
426
  font-weight: bold;
427
  cursor: pointer;
428
+ border-radius: 4px;
429
  }
430
  .quantity-selector input {
431
  width: 40px;
 
434
  background-color: #f8f9fa;
435
  font-size: 1rem;
436
  margin: 0 5px;
437
+ border-radius: 4px;
438
  }
439
  .customization-section {
440
  display: none;
 
448
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
449
  z-index: 10;
450
  border: 2px solid #fdf4e3;
451
+ max-height: 300px;
452
+ overflow-y: auto;
453
  }
454
  .customization-section.show {
455
  display: block;
 
461
  .customization-section label {
462
  display: block;
463
  margin-bottom: 5px;
464
+ font-size: 0.9rem;
465
  }
466
  .customization-section textarea {
467
  width: 100%;
 
470
  padding: 5px;
471
  border: 1px solid #ccc;
472
  border-radius: 5px;
473
+ font-size: 0.9rem;
474
  }
475
  .customization-actions {
476
  display: flex;
477
  justify-content: space-between;
478
+ margin-top: 15px;
479
  }
480
  .customization-actions button {
481
  padding: 8px;
 
484
  cursor: pointer;
485
  width: 48%;
486
  text-align: center;
487
+ font-size: 0.9rem;
488
+ color: #fff;
489
  }
490
  .add-to-cart-btn {
491
  background-color: #A52A2A;
 
492
  }
493
  .cancel-customization-btn {
494
  background-color: #6c757d;
 
495
  }
496
  .bill-item {
497
  display: flex;
 
679
  let currentCart = null;
680
  let menuItems = [];
681
  let selectedItem = null;
682
+ let availableAddOns = [];
683
 
684
+ // Fetch add-ons when the modal is opened
685
+ function fetchAddOns() {
686
+ return fetch('/cart/fetch_add_ons', {
687
+ method: 'GET',
688
+ headers: { 'Content-Type': 'application/json' }
689
+ })
690
+ .then(response => response.json())
691
+ .then(data => {
692
+ if (data.success) {
693
+ availableAddOns = data.add_ons;
694
+ } else {
695
+ console.error('Error fetching add-ons:', data.error);
696
+ availableAddOns = [];
697
+ }
698
+ })
699
+ .catch(err => {
700
+ console.error('Error fetching add-ons:', err);
701
+ availableAddOns = [];
702
+ });
703
+ }
704
 
705
  function updateQuantity(action, itemName, customerEmail) {
706
  let quantityInput = document.querySelector(`input[data-item-name="${itemName}"]`);
 
771
  if (selectedCoupon === "" || selectedCoupon === "None" || selectedCoupon === "Null") {
772
  selectedCoupon = null;
773
  }
774
+ // Fetch add-ons before displaying the modal
775
+ fetchAddOns().then(() => {
776
+ fetch('/cart/checkout', {
777
+ method: 'POST',
778
+ headers: { 'Content-Type': 'application/json' },
779
+ body: JSON.stringify({ selectedCoupon: selectedCoupon })
780
+ })
781
+ .then(response => response.json())
782
+ .then(data => {
783
+ if (data.success) {
784
+ currentCart = data.cart;
785
+ menuItems = data.menu_items;
786
+ displayAnythingElse();
787
+ } else {
788
+ alert(data.error || data.message);
789
+ }
790
+ })
791
+ .catch(err => {
792
+ console.error('Error during checkout:', err);
793
+ alert('An error occurred. Please try again.');
794
+ });
795
  });
796
  }
797
 
 
809
  <small>$${item.Price__c.toFixed(2)}</small>
810
  </div>
811
  <button class="add-back-button" onclick="showQuantitySelector('${item.Name}', ${item.Price__c}, '${item.Image1__c}', this)">+</button>
812
+ <div class="quantity-selector" data-item-name="${item.Name}">
813
  <button onclick="updateMenuItemQuantity('${item.Name}', 'decrease')">-</button>
814
  <input type="text" value="1" readonly data-item-name="${item.Name}">
815
  <button onclick="updateMenuItemQuantity('${item.Name}', 'increase')">+</button>
816
  </div>
817
  <div class="customization-section" data-item-name="${item.Name}">
818
  <h4>Customize ${item.Name}</h4>
819
+ <div id="addOns-${item.Name}">
820
+ <!-- Add-ons will be populated dynamically -->
 
 
 
 
 
 
821
  </div>
822
  <div>
823
  <strong>Special Instructions</strong>
 
830
  </div>
831
  `;
832
  menuItemsContainer.appendChild(itemElement);
833
+ // Populate add-ons for this item
834
+ const addOnsContainer = document.getElementById(`addOns-${item.Name}`);
835
+ addOnsContainer.innerHTML = `
836
+ <strong>Add-Ons</strong>
837
+ ${availableAddOns.length > 0 ? availableAddOns.map(addon => `
838
+ <label>
839
+ <input type="checkbox" value="${addon.name}" data-price="${addon.price}">
840
+ ${addon.name}
841
+ </label>
842
+ `).join('') : '<p>No add-ons available</p>'}
843
+ `;
844
  });
845
  document.getElementById('anythingElseModal').style.display = 'flex';
846
  }
 
849
  // Hide all quantity selectors and customization sections
850
  document.querySelectorAll('.quantity-selector').forEach(selector => {
851
  selector.style.display = 'none';
852
+ selector.querySelector('input').value = 1; // Reset quantity
853
  });
854
  document.querySelectorAll('.customization-section').forEach(section => {
855
  section.classList.remove('show');
856
+ section.querySelectorAll('input[type="checkbox"]').forEach(checkbox => {
857
+ checkbox.checked = false; // Reset add-ons
858
+ });
859
+ section.querySelector('textarea').value = ''; // Reset instructions
860
  });
861
  document.querySelectorAll('.add-back-button').forEach(btn => {
862
  btn.style.display = 'inline-block';
863
  });
864
 
865
+ // Show quantity selector and customization for the clicked item
866
  const quantitySelector = buttonElement.nextElementSibling;
867
  quantitySelector.style.display = 'flex';
868
  buttonElement.style.display = 'none';
869
 
 
870
  const customizationSection = quantitySelector.nextElementSibling;
871
  customizationSection.classList.add('show');
872
 
 
874
  }
875
 
876
  function updateMenuItemQuantity(itemName, action) {
877
+ const quantityInput = document.querySelector(`.quantity-selector[data-item-name="${itemName}"] input`);
878
  let quantity = parseInt(quantityInput.value);
879
  if (action === 'increase') {
880
  quantity++;
881
  } else if (action === 'decrease' && quantity > 1) {
882
  quantity--;
883
  }
884
+ if (isNaN(quantity) || quantity < 1) {
885
+ quantity = 1;
886
+ }
887
  quantityInput.value = quantity;
888
  }
889
 
890
  function cancelCustomization(itemName) {
891
+ const quantitySelector = document.querySelector(`.quantity-selector[data-item-name="${itemName}"]`);
892
  const customizationSection = quantitySelector.nextElementSibling;
893
  const addButton = quantitySelector.previousElementSibling;
894
 
 
907
  }
908
 
909
  function addToCartWithCustomizations(itemName, itemPrice, itemImage) {
910
+ const quantitySelector = document.querySelector(`.quantity-selector[data-item-name="${itemName}"]`);
911
+ const quantity = parseInt(quantitySelector.querySelector('input').value);
912
+ if (isNaN(quantity) || quantity < 1) {
913
+ alert('Invalid quantity!');
914
+ return;
915
+ }
916
  const customizationSection = document.querySelector(`.customization-section[data-item-name="${itemName}"]`);
917
  const addOns = Array.from(customizationSection.querySelectorAll('input[type="checkbox"]:checked')).map(checkbox => checkbox.value);
918
  const instructions = customizationSection.querySelector('textarea').value.trim();
 
942
  alert('Error adding item to cart: ' + data.error);
943
  }
944
  })
945
+ .catch(err => {
946
+ console.error('Error adding item:', err);
947
+ alert('An error occurred while adding the item to the cart.');
948
+ });
949
  }
950
 
951
  function closeAnythingElseModal() {
 
1045
  item_image: itemImage,
1046
  addons: [],
1047
  instructions: "",
1048
+ customer_email: customerEmail,
1049
+ quantity: 1
1050
  };
1051
  fetch('/cart/add_suggestion_to_cart', {
1052
  method: 'POST',