nagasurendra commited on
Commit
abbbe59
·
verified ·
1 Parent(s): 387755a

Update templates/menu.html

Browse files
Files changed (1) hide show
  1. templates/menu.html +63 -82
templates/menu.html CHANGED
@@ -592,90 +592,71 @@ form-check-input addon-option{
592
  <!-- JavaScript -->
593
  <script>
594
  // Show item details and fetch customization options
595
- function showItemDetails(name, price, image, description, section, selectedCategory) {
596
- // Fetch previous order details for the current user
597
- fetch(`/fetch_previous_order?email=${encodeURIComponent(userEmail)}`)
598
- .then(response => response.json())
599
- .then(data => {
600
- if (!data.success) {
601
- console.error("Error fetching previous order");
602
- return;
603
- }
604
-
605
- const previousOrder = data.previousOrder;
606
-
607
- // Find the specific item in the previous order
608
- const previousItem = previousOrder.find(item => item.name === name);
609
-
610
- // Set the modal details as usual
611
- document.getElementById('modal-name').innerText = name;
612
- document.getElementById('modal-price').innerText = `$${price}`;
613
- document.getElementById('modal-img').src = image || '/static/placeholder.jpg';
614
- document.getElementById('modal-description').innerText = description || 'No description available.';
615
- document.getElementById('addons-list').innerHTML = 'Loading customization options...';
616
- document.getElementById('modal-instructions').value = '';
617
- const modalSectionEl = document.getElementById('modal-section');
618
- modalSectionEl.setAttribute('data-section', section);
619
- modalSectionEl.setAttribute('data-category', selectedCategory);
620
-
621
- // Set the default quantity to 1 (or based on previous order)
622
- document.getElementById('quantityInput').value = previousItem ? previousItem.quantity : 1;
623
-
624
- // Fetch customization options based on the section
625
- fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
626
- .then(response => response.json())
627
- .then(data => {
628
- const addonsList = document.getElementById('addons-list');
629
- addonsList.innerHTML = ''; // Clear previous content
630
-
631
- if (!data.success || !data.addons || data.addons.length === 0) {
632
- addonsList.innerHTML = '<p>No customization options available.</p>';
633
- return;
634
- }
635
-
636
- // Pre-select the add-ons based on previous selection
637
- data.addons.forEach(addon => {
638
- const sectionDiv = document.createElement('div');
639
- sectionDiv.classList.add('addon-section'); // Add styling class
640
-
641
- // Add section title
642
- const title = document.createElement('h6');
643
- title.innerText = addon.name;
644
- sectionDiv.appendChild(title);
645
-
646
- // Create options list
647
- const optionsContainer = document.createElement('div');
648
- addon.options.forEach((option, index) => {
649
- const optionId = `addon-${addon.name.replace(/\s+/g, '')}-${index}`;
650
- const listItem = document.createElement('div');
651
- listItem.classList.add('form-check');
652
-
653
- // Check if this option was selected before
654
- const checked = previousItem.addons.includes(option); // Pre-select based on previous addons
655
-
656
- listItem.innerHTML = `
657
- <input type="checkbox" class="form-check-input addon-option" id="${optionId}" value="${option}" ${checked ? 'checked' : ''}
658
- data-name="${option}" data-group="${addon.name}" data-price="${addon.extra_charge ? addon.extra_charge_amount : 0}">
659
- <label class="form-check-label" for="${optionId}">
660
- ${option} ${addon.extra_charge ? `($${addon.extra_charge_amount})` : ''}
661
- </label>
662
- `;
663
- optionsContainer.appendChild(listItem);
664
- });
665
-
666
- sectionDiv.appendChild(optionsContainer);
667
- addonsList.appendChild(sectionDiv);
668
  });
669
- })
670
- .catch(err => {
671
- console.error('Error fetching add-ons:', err);
672
- document.getElementById('addons-list').innerHTML = '<p>Error loading customization options.</p>';
673
  });
674
- })
675
- .catch(err => {
676
- console.error('Error fetching previous order:', err);
677
- });
678
- }
 
 
 
 
 
 
 
 
679
 
680
  function handleToggle(source) {
681
  const form = document.getElementById("filter-form");
 
592
  <!-- JavaScript -->
593
  <script>
594
  // Show item details and fetch customization options
595
+ function showItemDetails(name, price, image, description, section, selectedCategory) {
596
+ document.getElementById('modal-name').innerText = name;
597
+ document.getElementById('modal-price').innerText = `$${price}`;
598
+ document.getElementById('modal-img').src = image || '/static/placeholder.jpg';
599
+ document.getElementById('modal-description').innerText = description || 'No description available.';
600
+ document.getElementById('addons-list').innerHTML = 'Loading customization options...';
601
+ document.getElementById('modal-instructions').value = '';
602
+ const modalSectionEl = document.getElementById('modal-section');
603
+ modalSectionEl.setAttribute('data-section', section);
604
+ modalSectionEl.setAttribute('data-category', selectedCategory);
605
+ // Set the default quantity to 1
606
+ document.getElementById('quantityInput').value = 1;
607
+
608
+ // Fetch customization options based on the section
609
+ fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
610
+ .then(response => response.json())
611
+ .then(data => {
612
+ const addonsList = document.getElementById('addons-list');
613
+ addonsList.innerHTML = ''; // Clear previous content
614
+ if (!data.success || !data.addons || data.addons.length === 0) {
615
+ addonsList.innerHTML = '<p>No customization options available.</p>';
616
+ return;
617
+ }
618
+
619
+ // Display customization options inside styled divs
620
+ data.addons.forEach(addon => {
621
+ const sectionDiv = document.createElement('div');
622
+ sectionDiv.classList.add('addon-section'); // Add styling class
623
+
624
+ // Add section title
625
+ const title = document.createElement('h6');
626
+ title.innerText = addon.name;
627
+ sectionDiv.appendChild(title);
628
+
629
+ // Create options list
630
+ const optionsContainer = document.createElement('div');
631
+ addon.options.forEach((option, index) => {
632
+ const optionId = `addon-${addon.name.replace(/\s+/g, '')}-${index}`;
633
+ const listItem = document.createElement('div');
634
+ listItem.classList.add('form-check');
635
+ listItem.innerHTML = `
636
+ <input type="checkbox" class="form-check-input addon-option" id="${optionId}" value="${option}"
637
+ data-name="${option}" data-group="${addon.name}" data-price="${addon.extra_charge ? addon.extra_charge_amount : 0}">
638
+ <label class="form-check-label" for="${optionId}">
639
+ ${option} ${addon.extra_charge ? `($${addon.extra_charge_amount})` : ''}
640
+ </label>
641
+ `;
642
+ optionsContainer.appendChild(listItem);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
643
  });
644
+ sectionDiv.appendChild(optionsContainer);
645
+ addonsList.appendChild(sectionDiv);
 
 
646
  });
647
+ })
648
+ .catch(err => {
649
+ console.error('Error fetching add-ons:', err);
650
+ document.getElementById('addons-list').innerHTML = '<p>Error loading customization options.</p>';
651
+ });
652
+ }
653
+ along with it we are storing details like # Store all order details (before deleting cart items)
654
+ order_details = "\n".join(
655
+ f"{item['Name']} x{item['Quantity__c']} | Add-Ons: {item.get('Add_Ons__c', 'None')} | "
656
+ f"Instructions: {item.get('Instructions__c', 'None')} | "
657
+ f"Price: ${item['Price__c']} | Image: {item['Image1__c']}"
658
+ for item in cart_items
659
+ )
660
 
661
  function handleToggle(source) {
662
  const form = document.getElementById("filter-form");