lokeshloki143 commited on
Commit
149904f
·
verified ·
1 Parent(s): 11260d4

Update templates/cart.html

Browse files
Files changed (1) hide show
  1. templates/cart.html +219 -10
templates/cart.html CHANGED
@@ -146,9 +146,6 @@
146
  color: #ffffff;
147
  }
148
  .add-back-button {
149
- position: absolute;
150
- top: -5px;
151
- right: -10px;
152
  font-size: 1rem;
153
  padding: 0;
154
  width: 30px;
@@ -156,16 +153,13 @@
156
  background-color: #fff;
157
  color: #0FAA39;
158
  border: 2px solid #0FAA39;
159
- border-radius: 0;
160
  cursor: pointer;
161
  transition: background-color 0.3s, color 0.3s, border-color 0.3s;
162
- z-index: 2;
163
  }
164
  .add-back-button:hover {
165
- background-color: #fff;
166
- color: #0FAA39;
167
- border-color: #0FAA39;
168
- z-index: 3;
169
  }
170
  .cart-item-details {
171
  flex: 1;
@@ -393,6 +387,7 @@
393
  background-color: #fff;
394
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
395
  border: 2px solid #fdf4e3;
 
396
  }
397
  .menu-item img {
398
  width: 50px;
@@ -401,6 +396,9 @@
401
  border-radius: 5px;
402
  margin-right: 10px;
403
  }
 
 
 
404
  .menu-item-details {
405
  flex-grow: 1;
406
  }
@@ -408,6 +406,80 @@
408
  display: block;
409
  color: #666;
410
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
  .bill-item {
412
  display: flex;
413
  justify-content: space-between;
@@ -593,6 +665,14 @@
593
  <script>
594
  let currentCart = null;
595
  let menuItems = [];
 
 
 
 
 
 
 
 
596
 
597
  function updateQuantity(action, itemName, customerEmail) {
598
  let quantityInput = document.querySelector(`input[data-item-name="${itemName}"]`);
@@ -697,15 +777,144 @@
697
  <small>${item.Veg_NonVeg__c} | ${item.Section__c}</small>
698
  <small>$${item.Price__c.toFixed(2)}</small>
699
  </div>
700
- <button class="add-back-button" onclick="addToCartSuggestion('${item.Name}', '${item.Price__c}', '${item.Image1__c}')">+</button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
701
  `;
702
  menuItemsContainer.appendChild(itemElement);
703
  });
704
  document.getElementById('anythingElseModal').style.display = 'flex';
705
  }
706
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
707
  function closeAnythingElseModal() {
708
  document.getElementById('anythingElseModal').style.display = 'none';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
709
  }
710
 
711
  function showBill() {
 
146
  color: #ffffff;
147
  }
148
  .add-back-button {
 
 
 
149
  font-size: 1rem;
150
  padding: 0;
151
  width: 30px;
 
153
  background-color: #fff;
154
  color: #0FAA39;
155
  border: 2px solid #0FAA39;
156
+ border-radius: 50%;
157
  cursor: pointer;
158
  transition: background-color 0.3s, color 0.3s, border-color 0.3s;
 
159
  }
160
  .add-back-button:hover {
161
+ background-color: #0FAA39;
162
+ color: #fff;
 
 
163
  }
164
  .cart-item-details {
165
  flex: 1;
 
387
  background-color: #fff;
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;
 
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
  }
 
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;
424
+ text-align: center;
425
+ border: none;
426
+ background-color: #f8f9fa;
427
+ font-size: 1rem;
428
+ margin: 0 5px;
429
+ }
430
+ .customization-section {
431
+ display: none;
432
+ position: absolute;
433
+ top: 100%;
434
+ left: 0;
435
+ right: 0;
436
+ background-color: #fff;
437
+ padding: 15px;
438
+ border-radius: 8px;
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;
445
+ }
446
+ .customization-section h4 {
447
+ font-size: 1.2rem;
448
+ margin-bottom: 10px;
449
+ }
450
+ .customization-section label {
451
+ display: block;
452
+ margin-bottom: 5px;
453
+ }
454
+ .customization-section textarea {
455
+ width: 100%;
456
+ height: 60px;
457
+ margin-top: 10px;
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;
469
+ border: none;
470
+ border-radius: 5px;
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;
485
  justify-content: space-between;
 
665
  <script>
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}"]`);
 
777
  <small>${item.Veg_NonVeg__c} | ${item.Section__c}</small>
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>
799
+ <textarea placeholder="e.g., Less spicy"></textarea>
800
+ </div>
801
+ <div class="customization-actions">
802
+ <button class="add-to-cart-btn" onclick="addToCartWithCustomizations('${item.Name}', ${item.Price__c}, '${item.Image1__c}')">Add to Cart</button>
803
+ <button class="cancel-customization-btn" onclick="cancelCustomization('${item.Name}')">Cancel</button>
804
+ </div>
805
+ </div>
806
  `;
807
  menuItemsContainer.appendChild(itemElement);
808
  });
809
  document.getElementById('anythingElseModal').style.display = 'flex';
810
  }
811
 
812
+ function showQuantitySelector(itemName, itemPrice, itemImage, buttonElement) {
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
+
833
+ selectedItem = { name: itemName, price: itemPrice, image: itemImage };
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
+
852
+ // Reset quantity
853
+ quantitySelector.querySelector('input').value = 1;
854
+ // Hide quantity selector and customization section
855
+ quantitySelector.style.display = 'none';
856
+ customizationSection.classList.remove('show');
857
+ // Show add button
858
+ addButton.style.display = 'inline-block';
859
+ // Reset add-ons and instructions
860
+ customizationSection.querySelectorAll('input[type="checkbox"]').forEach(checkbox => {
861
+ checkbox.checked = false;
862
+ });
863
+ customizationSection.querySelector('textarea').value = '';
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();
872
+ const customerEmail = "{{ customer_email }}";
873
+
874
+ const data = {
875
+ item_name: itemName,
876
+ item_price: itemPrice,
877
+ item_image: itemImage,
878
+ addons: addOns,
879
+ instructions: instructions,
880
+ customer_email: customerEmail,
881
+ quantity: quantity
882
+ };
883
+
884
+ fetch('/cart/add_suggestion_to_cart', {
885
+ method: 'POST',
886
+ headers: { 'Content-Type': 'application/json' },
887
+ body: JSON.stringify(data)
888
+ })
889
+ .then(response => response.json())
890
+ .then(data => {
891
+ if (data.success) {
892
+ alert('Item added to cart!');
893
+ location.reload();
894
+ } else {
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() {
902
  document.getElementById('anythingElseModal').style.display = 'none';
903
+ // Reset all quantity selectors and customization sections
904
+ document.querySelectorAll('.quantity-selector').forEach(selector => {
905
+ selector.style.display = 'none';
906
+ selector.querySelector('input').value = 1;
907
+ });
908
+ document.querySelectorAll('.customization-section').forEach(section => {
909
+ section.classList.remove('show');
910
+ section.querySelectorAll('input[type="checkbox"]').forEach(checkbox => {
911
+ checkbox.checked = false;
912
+ });
913
+ section.querySelector('textarea').value = '';
914
+ });
915
+ document.querySelectorAll('.add-back-button').forEach(btn => {
916
+ btn.style.display = 'inline-block';
917
+ });
918
  }
919
 
920
  function showBill() {