Update templates/menu.html
Browse files- templates/menu.html +211 -212
    	
        templates/menu.html
    CHANGED
    
    | @@ -521,240 +521,239 @@ form.text-center.mb-4 { | |
| 521 | 
             
                </div>
         | 
| 522 |  | 
| 523 | 
             
                <!-- JavaScript -->
         | 
| 524 | 
            -
             | 
| 525 | 
            -
             | 
| 526 | 
            -
             | 
| 527 | 
            -
             | 
| 528 | 
            -
             | 
| 529 | 
            -
             | 
| 530 | 
            -
             | 
| 531 | 
            -
             | 
| 532 | 
            -
                        // Set section and category for reference
         | 
| 533 | 
            -
                        const modalSectionEl = document.getElementById('modal-section');
         | 
| 534 | 
            -
                        modalSectionEl.setAttribute('data-section', section);
         | 
| 535 | 
            -
                        modalSectionEl.setAttribute('data-category', selectedCategory);
         | 
| 536 | 
            -
                        // Fetch customization options based on the section
         | 
| 537 | 
            -
                        fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
         | 
| 538 | 
            -
                            .then(response => response.json())
         | 
| 539 | 
            -
                            .then(data => {
         | 
| 540 | 
            -
                                const addonsList = document.getElementById('addons-list');
         | 
| 541 | 
            -
                                addonsList.innerHTML = ''; // Clear previous content
         | 
| 542 |  | 
| 543 | 
            -
             | 
| 544 | 
            -
             | 
| 545 | 
            -
             | 
| 546 | 
            -
             | 
| 547 | 
            -
             | 
| 548 | 
            -
             | 
| 549 | 
            -
             | 
| 550 | 
            -
             | 
| 551 | 
            -
             | 
| 552 | 
            -
             | 
| 553 | 
            -
             | 
| 554 | 
            -
             | 
| 555 | 
            -
             | 
| 556 | 
            -
             | 
| 557 | 
            -
             | 
| 558 | 
            -
             | 
| 559 | 
            -
             | 
| 560 | 
            -
             | 
| 561 | 
            -
             | 
| 562 | 
            -
             | 
| 563 | 
            -
             | 
| 564 | 
            -
             | 
| 565 | 
            -
             | 
| 566 | 
            -
             | 
| 567 | 
            -
             | 
| 568 | 
            -
             | 
| 569 | 
            -
             | 
| 570 | 
            -
             | 
| 571 | 
            -
                                     | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 572 | 
             
                                });
         | 
| 573 | 
            -
             | 
| 574 | 
            -
             | 
| 575 | 
            -
                                console.error('Error fetching add-ons:', err);
         | 
| 576 | 
            -
                                document.getElementById('addons-list').innerHTML = '<p>Error loading customization options.</p>';
         | 
| 577 | 
             
                            });
         | 
| 578 | 
            -
             | 
|  | |
|  | |
|  | |
|  | |
|  | |
| 579 |  | 
| 580 | 
            -
             | 
| 581 | 
            -
             | 
| 582 | 
            -
             | 
| 583 | 
            -
             | 
| 584 | 
            -
             | 
| 585 | 
            -
                
         | 
| 586 | 
            -
                // Hide all items initially
         | 
| 587 | 
            -
                items.forEach(item => {
         | 
| 588 | 
            -
                    let itemName = item.querySelector('.card-title').innerText.toLowerCase(); // Get item name
         | 
| 589 | 
            -
                    let itemSection = item.closest('.row').previousElementSibling.innerText.toLowerCase(); // Get section name
         | 
| 590 |  | 
| 591 | 
            -
                    //  | 
| 592 | 
            -
                     | 
| 593 | 
            -
                         | 
| 594 | 
            -
                         | 
| 595 | 
            -
             | 
| 596 | 
            -
                         | 
| 597 | 
            -
             | 
| 598 | 
            -
             | 
| 599 | 
            -
             | 
| 600 | 
            -
             | 
| 601 | 
            -
             | 
| 602 | 
            -
             | 
| 603 | 
            -
                     | 
| 604 | 
            -
             | 
| 605 | 
            -
             | 
| 606 | 
            -
                     | 
| 607 | 
            -
                         | 
| 608 | 
            -
                        sectionRow | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 609 | 
             
                    }
         | 
| 610 | 
            -
                });
         | 
| 611 | 
            -
            }
         | 
| 612 |  | 
| 613 | 
            -
             | 
| 614 | 
            -
             | 
| 615 | 
            -
             | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 616 |  | 
| 617 | 
            -
             | 
| 618 | 
            -
             | 
| 619 | 
            -
             | 
| 620 | 
            -
                     | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 621 | 
             
                }
         | 
| 622 |  | 
| 623 | 
            -
                 | 
| 624 | 
            -
             | 
| 625 | 
            -
             | 
| 626 | 
            -
             | 
| 627 | 
            -
                const selectedCategory = modalSectionEl.getAttribute('data-category');
         | 
| 628 | 
            -
                if (!itemName || !itemPrice || !section || !itemImage) {
         | 
| 629 | 
            -
                    console.error('Missing data for cart item:', { itemName, itemPrice, section, itemImage});
         | 
| 630 | 
            -
                    return;
         | 
| 631 | 
            -
                }
         | 
| 632 | 
            -
               
         | 
| 633 | 
            -
                // Collect selected add-ons
         | 
| 634 | 
            -
                let selectedAddOns = Array.from(
         | 
| 635 | 
            -
                    document.querySelectorAll('#addons-list input[type="checkbox"]:checked')
         | 
| 636 | 
            -
                ).map(addon => ({
         | 
| 637 | 
            -
                    name: addon.getAttribute('data-name') || 'Default Name', // Fallback Name
         | 
| 638 | 
            -
                    price: parseFloat(addon.getAttribute('data-price') || 0)
         | 
| 639 | 
            -
                }));
         | 
| 640 | 
            -
             | 
| 641 | 
            -
                // Get the selected quantity
         | 
| 642 | 
            -
                const quantity = parseInt(document.getElementById('quantityInput').value) || 1; // Default to 1 if invalid
         | 
| 643 | 
            -
             | 
| 644 | 
            -
                const instructions = document.getElementById('modal-instructions').value;
         | 
| 645 | 
            -
             | 
| 646 | 
            -
                // Prepare data for the cart
         | 
| 647 | 
            -
                const cartPayload = {
         | 
| 648 | 
            -
                    itemName: itemName,
         | 
| 649 | 
            -
                    itemPrice: itemPrice,
         | 
| 650 | 
            -
                    itemImage: itemImage,
         | 
| 651 | 
            -
                    section: section,
         | 
| 652 | 
            -
                    category: selectedCategory,
         | 
| 653 | 
            -
                    addons: selectedAddOns,
         | 
| 654 | 
            -
                    instructions: instructions,
         | 
| 655 | 
            -
                    quantity: quantity // Include the quantity
         | 
| 656 | 
            -
                };
         | 
| 657 | 
            -
             | 
| 658 | 
            -
                // Send the cart data to the server
         | 
| 659 | 
            -
                fetch('/cart/add', {
         | 
| 660 | 
            -
                    method: 'POST',
         | 
| 661 | 
            -
                    headers: {
         | 
| 662 | 
            -
                        'Content-Type': 'application/json',
         | 
| 663 | 
            -
                    },
         | 
| 664 | 
            -
                    body: JSON.stringify(cartPayload)
         | 
| 665 | 
            -
                })
         | 
| 666 | 
            -
                .then(response => response.json())
         | 
| 667 | 
            -
                .then(data => {
         | 
| 668 | 
            -
                    if (data.success) {
         | 
| 669 | 
            -
                        alert('Item added to cart successfully!');
         | 
| 670 | 
            -
                        updateCartUI(data.cart); // Update cart UI after adding an item
         | 
| 671 | 
            -
                        const modal = document.getElementById('itemModal');
         | 
| 672 | 
            -
                        const modalInstance = bootstrap.Modal.getInstance(modal);
         | 
| 673 | 
            -
                        modalInstance.hide();
         | 
| 674 | 
            -
                    } else {
         | 
| 675 | 
            -
                        alert(data.error || 'Failed to add item to cart.');
         | 
| 676 | 
             
                    }
         | 
| 677 | 
            -
                })
         | 
| 678 | 
            -
                .catch(err => {
         | 
| 679 | 
            -
                    console.error('Error adding item to cart:', err);
         | 
| 680 | 
            -
                    alert('An error occurred while adding the item to the cart.');
         | 
| 681 | 
            -
                });
         | 
| 682 | 
            -
            }
         | 
| 683 |  | 
| 684 | 
            -
             | 
| 685 | 
            -
             | 
| 686 | 
            -
                    console.error('Invalid cart data:', cart);
         | 
| 687 | 
            -
                    return;
         | 
| 688 | 
             
                }
         | 
| 689 | 
            -
                const cartIcon = document.getElementById('cart-icon');
         | 
| 690 | 
            -
                cartIcon.innerText = cart.length;  // Assuming cart is an array of items
         | 
| 691 | 
            -
            }
         | 
| 692 |  | 
| 693 | 
            -
            function updateCartDisplay(cart) {
         | 
| 694 | 
            -
             | 
| 695 | 
            -
             | 
| 696 | 
            -
             | 
| 697 | 
            -
                }
         | 
| 698 | 
            -
                const cartCountElement = document.getElementById('cart-count');
         | 
| 699 | 
            -
                cartCountElement.innerText = cart.length;  // Update cart item count
         | 
| 700 | 
            -
                // Optionally, show a small success notification that the item was added
         | 
| 701 | 
            -
                const successNotification = document.createElement('div');
         | 
| 702 | 
            -
                successNotification.classList.add('success-notification');
         | 
| 703 | 
            -
                successNotification.innerText = 'Item added to cart!';
         | 
| 704 | 
            -
                document.body.appendChild(successNotification);
         | 
| 705 | 
            -
                setTimeout(() => {
         | 
| 706 | 
            -
                    successNotification.remove(); // Remove success notification after a few seconds
         | 
| 707 | 
            -
                }, 2000);
         | 
| 708 | 
            -
            }
         | 
| 709 | 
            -
            document.addEventListener('DOMContentLoaded', function () {
         | 
| 710 | 
            -
                // Get references to the quantity buttons and the input field
         | 
| 711 | 
            -
                const decreaseBtn = document.getElementById('decreaseQuantity');
         | 
| 712 | 
            -
                const increaseBtn = document.getElementById('increaseQuantity');
         | 
| 713 | 
            -
                const quantityInput = document.getElementById('quantityInput');
         | 
| 714 | 
            -
             | 
| 715 | 
            -
                // Add event listener to decrease button
         | 
| 716 | 
            -
                decreaseBtn.addEventListener('click', function () {
         | 
| 717 | 
            -
                    let currentQuantity = parseInt(quantityInput.value);
         | 
| 718 | 
            -
                    if (currentQuantity > 1) {
         | 
| 719 | 
            -
                        currentQuantity--;
         | 
| 720 | 
            -
                        quantityInput.value = currentQuantity;
         | 
| 721 | 
             
                    }
         | 
| 722 | 
            -
                });
         | 
| 723 |  | 
| 724 | 
            -
             | 
| 725 | 
            -
             | 
| 726 | 
            -
                     | 
| 727 | 
            -
                     | 
| 728 | 
            -
                     | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 729 | 
             
                });
         | 
| 730 | 
            -
            });
         | 
| 731 |  | 
| 732 | 
             
                // Function to round reward points to a single digit
         | 
| 733 | 
            -
            function roundRewardPoints() {
         | 
| 734 | 
            -
             | 
| 735 | 
            -
             | 
| 736 | 
            -
             | 
| 737 | 
            -
             | 
| 738 | 
            -
             | 
| 739 | 
            -
             | 
| 740 | 
            -
             | 
| 741 | 
            -
             | 
| 742 | 
            -
             | 
| 743 | 
            -
             | 
| 744 | 
            -
             | 
| 745 | 
            -
                    if (!isNaN(rewardPoints)) {
         | 
| 746 | 
            -
                        rewardPointsElement.innerText = rewardPoints.toFixed(1); // Round to 1 decimal place
         | 
| 747 | 
             
                    } else {
         | 
| 748 | 
            -
                        console.error("Reward points  | 
| 749 | 
             
                    }
         | 
| 750 | 
            -
                } else {
         | 
| 751 | 
            -
                    console.error("Reward points element is missing.");
         | 
| 752 | 
             
                }
         | 
| 753 | 
            -
             | 
| 754 | 
            -
             | 
| 755 | 
            -
             | 
| 756 | 
            -
                    
         | 
| 757 | 
            -
                </script>
         | 
| 758 |  | 
| 759 | 
             
                <!-- Bootstrap JS -->
         | 
| 760 | 
             
                <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
         | 
|  | |
| 521 | 
             
                </div>
         | 
| 522 |  | 
| 523 | 
             
                <!-- JavaScript -->
         | 
| 524 | 
            +
               <script>
         | 
| 525 | 
            +
                function showItemDetails(name, price, image, description, section, selectedCategory) {
         | 
| 526 | 
            +
                    document.getElementById('modal-name').innerText = name;
         | 
| 527 | 
            +
                    document.getElementById('modal-price').innerText = `$${price}`;
         | 
| 528 | 
            +
                    document.getElementById('modal-img').src = image || '/static/placeholder.jpg';
         | 
| 529 | 
            +
                    document.getElementById('modal-description').innerText = description || 'No description available.';
         | 
| 530 | 
            +
                    document.getElementById('addons-list').innerHTML = 'Loading customization options...';
         | 
| 531 | 
            +
                    document.getElementById('modal-instructions').value = '';
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 532 |  | 
| 533 | 
            +
                    // Set section and category for reference
         | 
| 534 | 
            +
                    const modalSectionEl = document.getElementById('modal-section');
         | 
| 535 | 
            +
                    modalSectionEl.setAttribute('data-section', section);
         | 
| 536 | 
            +
                    modalSectionEl.setAttribute('data-category', selectedCategory);
         | 
| 537 | 
            +
                    
         | 
| 538 | 
            +
                    // Fetch customization options based on the section
         | 
| 539 | 
            +
                    fetch(`/api/addons?item_name=${encodeURIComponent(name)}&item_section=${encodeURIComponent(section)}`)
         | 
| 540 | 
            +
                        .then(response => response.json())
         | 
| 541 | 
            +
                        .then(data => {
         | 
| 542 | 
            +
                            const addonsList = document.getElementById('addons-list');
         | 
| 543 | 
            +
                            addonsList.innerHTML = ''; // Clear previous content
         | 
| 544 | 
            +
                    
         | 
| 545 | 
            +
                            if (!data.success || !data.addons || data.addons.length === 0) {
         | 
| 546 | 
            +
                                addonsList.innerHTML = '<p>No customization options available.</p>';
         | 
| 547 | 
            +
                                return;
         | 
| 548 | 
            +
                            }
         | 
| 549 | 
            +
             | 
| 550 | 
            +
                            // Display customization options inside styled divs
         | 
| 551 | 
            +
                            data.addons.forEach(addon => {
         | 
| 552 | 
            +
                                const sectionDiv = document.createElement('div');
         | 
| 553 | 
            +
                                sectionDiv.classList.add('addon-section'); // Add styling class
         | 
| 554 | 
            +
                                const title = document.createElement('h6');
         | 
| 555 | 
            +
                                title.innerText = addon.name;
         | 
| 556 | 
            +
                                sectionDiv.appendChild(title);
         | 
| 557 | 
            +
             | 
| 558 | 
            +
                                // Create options list
         | 
| 559 | 
            +
                                const optionsContainer = document.createElement('div');
         | 
| 560 | 
            +
                                addon.options.forEach((option, index) => {
         | 
| 561 | 
            +
                                    const optionId = `addon-${addon.name.replace(/\s+/g, '')}-${index}`;
         | 
| 562 | 
            +
                                    const listItem = document.createElement('div');
         | 
| 563 | 
            +
                                    listItem.classList.add('form-check');
         | 
| 564 | 
            +
                                    listItem.innerHTML = `
         | 
| 565 | 
            +
                                        <input type="checkbox" class="form-check-input addon-option" id="${optionId}" value="${option}"
         | 
| 566 | 
            +
                                               data-name="${option}" data-price="${addon.extra_charge ? addon.extra_charge_amount : 0}">
         | 
| 567 | 
            +
                                        <label class="form-check-label" for="${optionId}">
         | 
| 568 | 
            +
                                            ${option} ${addon.extra_charge ? `($${addon.extra_charge_amount})` : ''}
         | 
| 569 | 
            +
                                        </label>
         | 
| 570 | 
            +
                                    `;
         | 
| 571 | 
            +
                                    optionsContainer.appendChild(listItem);
         | 
| 572 | 
             
                                });
         | 
| 573 | 
            +
                                sectionDiv.appendChild(optionsContainer);
         | 
| 574 | 
            +
                                addonsList.appendChild(sectionDiv);
         | 
|  | |
|  | |
| 575 | 
             
                            });
         | 
| 576 | 
            +
                        })
         | 
| 577 | 
            +
                        .catch(err => {
         | 
| 578 | 
            +
                            console.error('Error fetching add-ons:', err);
         | 
| 579 | 
            +
                            document.getElementById('addons-list').innerHTML = '<p>Error loading customization options.</p>';
         | 
| 580 | 
            +
                        });
         | 
| 581 | 
            +
                }
         | 
| 582 |  | 
| 583 | 
            +
                function filterMenu() {
         | 
| 584 | 
            +
                    let input = document.getElementById('searchBar').value.toLowerCase(); // Get value from search bar
         | 
| 585 | 
            +
                    let sections = document.querySelectorAll('h3'); // Select section headers
         | 
| 586 | 
            +
                    let items = document.querySelectorAll('.menu-card'); // Select all items
         | 
| 587 | 
            +
                    let matchedSections = new Set(); // Store matched sections
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
| 588 |  | 
| 589 | 
            +
                    // Hide all items initially
         | 
| 590 | 
            +
                    items.forEach(item => {
         | 
| 591 | 
            +
                        let itemName = item.querySelector('.card-title').innerText.toLowerCase(); // Get item name
         | 
| 592 | 
            +
                        let itemSection = item.closest('.row').previousElementSibling.innerText.toLowerCase(); // Get section name
         | 
| 593 | 
            +
                        
         | 
| 594 | 
            +
                        // If search matches item name or section, show the item
         | 
| 595 | 
            +
                        if (itemName.includes(input) || (itemSection && itemSection.includes(input))) {
         | 
| 596 | 
            +
                            item.style.display = 'block';  // Show item if it matches search
         | 
| 597 | 
            +
                            matchedSections.add(item.closest('.row')); // Add section to matched list
         | 
| 598 | 
            +
                        } else {
         | 
| 599 | 
            +
                            item.style.display = 'none'; // Hide item if not matched
         | 
| 600 | 
            +
                        }
         | 
| 601 | 
            +
                    });
         | 
| 602 | 
            +
                    
         | 
| 603 | 
            +
                    // Show or hide sections based on matched items
         | 
| 604 | 
            +
                    sections.forEach(section => {
         | 
| 605 | 
            +
                        let sectionRow = section.nextElementSibling; // The row containing items
         | 
| 606 | 
            +
                        if (matchedSections.has(sectionRow)) {
         | 
| 607 | 
            +
                            section.style.display = 'block'; // Show section header
         | 
| 608 | 
            +
                            sectionRow.style.display = 'flex'; // Show section items
         | 
| 609 | 
            +
                        } else {
         | 
| 610 | 
            +
                            section.style.display = 'none'; // Hide section header
         | 
| 611 | 
            +
                            sectionRow.style.display = 'none'; // Hide section items
         | 
| 612 | 
            +
                        }
         | 
| 613 | 
            +
                    });
         | 
| 614 | 
            +
                }
         | 
| 615 | 
            +
             | 
| 616 | 
            +
                function addToCartFromModal() {
         | 
| 617 | 
            +
                    const itemName = document.getElementById('modal-name').innerText;
         | 
| 618 | 
            +
                    let itemPrice = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
         | 
| 619 | 
            +
             | 
| 620 | 
            +
                    // Validate item price
         | 
| 621 | 
            +
                    if (isNaN(itemPrice)) {
         | 
| 622 | 
            +
                        alert('Invalid price for the item. Please check the item details.');
         | 
| 623 | 
            +
                        return;
         | 
| 624 | 
             
                    }
         | 
|  | |
|  | |
| 625 |  | 
| 626 | 
            +
                    const itemImage = document.getElementById('modal-img').src;
         | 
| 627 | 
            +
                    const modalSectionEl = document.getElementById('modal-section');
         | 
| 628 | 
            +
                    const section = modalSectionEl.getAttribute('data-section');
         | 
| 629 | 
            +
                    const selectedCategory = modalSectionEl.getAttribute('data-category');
         | 
| 630 | 
            +
                    
         | 
| 631 | 
            +
                    if (!itemName || !itemPrice || !section || !itemImage) {
         | 
| 632 | 
            +
                        console.error('Missing data for cart item:', { itemName, itemPrice, section, itemImage });
         | 
| 633 | 
            +
                        return;
         | 
| 634 | 
            +
                    }
         | 
| 635 |  | 
| 636 | 
            +
                    // Collect selected add-ons
         | 
| 637 | 
            +
                    let selectedAddOns = Array.from(
         | 
| 638 | 
            +
                        document.querySelectorAll('#addons-list input[type="checkbox"]:checked')
         | 
| 639 | 
            +
                    ).map(addon => ({
         | 
| 640 | 
            +
                        name: addon.getAttribute('data-name') || 'Default Name', // Fallback Name
         | 
| 641 | 
            +
                        price: parseFloat(addon.getAttribute('data-price') || 0)
         | 
| 642 | 
            +
                    }));
         | 
| 643 | 
            +
             | 
| 644 | 
            +
                    // Get the selected quantity
         | 
| 645 | 
            +
                    const quantity = parseInt(document.getElementById('quantityInput').value) || 1; // Default to 1 if invalid
         | 
| 646 | 
            +
                    const instructions = document.getElementById('modal-instructions').value;
         | 
| 647 | 
            +
             | 
| 648 | 
            +
                    // Prepare data for the cart
         | 
| 649 | 
            +
                    const cartPayload = {
         | 
| 650 | 
            +
                        itemName: itemName,
         | 
| 651 | 
            +
                        itemPrice: itemPrice,
         | 
| 652 | 
            +
                        itemImage: itemImage,
         | 
| 653 | 
            +
                        section: section,
         | 
| 654 | 
            +
                        category: selectedCategory,
         | 
| 655 | 
            +
                        addons: selectedAddOns,
         | 
| 656 | 
            +
                        instructions: instructions,
         | 
| 657 | 
            +
                        quantity: quantity // Include the quantity
         | 
| 658 | 
            +
                    };
         | 
| 659 | 
            +
             | 
| 660 | 
            +
                    // Send the cart data to the server
         | 
| 661 | 
            +
                    fetch('/cart/add', {
         | 
| 662 | 
            +
                        method: 'POST',
         | 
| 663 | 
            +
                        headers: {
         | 
| 664 | 
            +
                            'Content-Type': 'application/json',
         | 
| 665 | 
            +
                        },
         | 
| 666 | 
            +
                        body: JSON.stringify(cartPayload)
         | 
| 667 | 
            +
                    })
         | 
| 668 | 
            +
                    .then(response => response.json())
         | 
| 669 | 
            +
                    .then(data => {
         | 
| 670 | 
            +
                        if (data.success) {
         | 
| 671 | 
            +
                            alert('Item added to cart successfully!');
         | 
| 672 | 
            +
                            updateCartUI(data.cart); // Update cart UI after adding an item
         | 
| 673 | 
            +
                            const modal = document.getElementById('itemModal');
         | 
| 674 | 
            +
                            const modalInstance = bootstrap.Modal.getInstance(modal);
         | 
| 675 | 
            +
                            modalInstance.hide();
         | 
| 676 | 
            +
                        } else {
         | 
| 677 | 
            +
                            alert(data.error || 'Failed to add item to cart.');
         | 
| 678 | 
            +
                        }
         | 
| 679 | 
            +
                    })
         | 
| 680 | 
            +
                    .catch(err => {
         | 
| 681 | 
            +
                        console.error('Error adding item to cart:', err);
         | 
| 682 | 
            +
                        alert('An error occurred while adding the item to the cart.');
         | 
| 683 | 
            +
                    });
         | 
| 684 | 
             
                }
         | 
| 685 |  | 
| 686 | 
            +
                function updateCartUI(cart) {
         | 
| 687 | 
            +
                    if (!Array.isArray(cart)) {
         | 
| 688 | 
            +
                        console.error('Invalid cart data:', cart);
         | 
| 689 | 
            +
                        return;
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 690 | 
             
                    }
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 691 |  | 
| 692 | 
            +
                    const cartIcon = document.getElementById('cart-icon');
         | 
| 693 | 
            +
                    cartIcon.innerText = cart.length;  // Assuming cart is an array of items
         | 
|  | |
|  | |
| 694 | 
             
                }
         | 
|  | |
|  | |
|  | |
| 695 |  | 
| 696 | 
            +
                function updateCartDisplay(cart) {
         | 
| 697 | 
            +
                    if (!Array.isArray(cart)) {
         | 
| 698 | 
            +
                        console.error('Invalid cart data:', cart);
         | 
| 699 | 
            +
                        return;
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 700 | 
             
                    }
         | 
|  | |
| 701 |  | 
| 702 | 
            +
                    const cartCountElement = document.getElementById('cart-count');
         | 
| 703 | 
            +
                    cartCountElement.innerText = cart.length;  // Update cart item count
         | 
| 704 | 
            +
                    
         | 
| 705 | 
            +
                    const successNotification = document.createElement('div');
         | 
| 706 | 
            +
                    successNotification.classList.add('success-notification');
         | 
| 707 | 
            +
                    successNotification.innerText = 'Item added to cart!';
         | 
| 708 | 
            +
                    document.body.appendChild(successNotification);
         | 
| 709 | 
            +
                    setTimeout(() => {
         | 
| 710 | 
            +
                        successNotification.remove(); // Remove success notification after a few seconds
         | 
| 711 | 
            +
                    }, 2000);
         | 
| 712 | 
            +
                }
         | 
| 713 | 
            +
             | 
| 714 | 
            +
                document.addEventListener('DOMContentLoaded', function () {
         | 
| 715 | 
            +
                    // Get references to the quantity buttons and the input field
         | 
| 716 | 
            +
                    const decreaseBtn = document.getElementById('decreaseQuantity');
         | 
| 717 | 
            +
                    const increaseBtn = document.getElementById('increaseQuantity');
         | 
| 718 | 
            +
                    const quantityInput = document.getElementById('quantityInput');
         | 
| 719 | 
            +
             | 
| 720 | 
            +
                    // Add event listener to decrease button
         | 
| 721 | 
            +
                    decreaseBtn.addEventListener('click', function () {
         | 
| 722 | 
            +
                        let currentQuantity = parseInt(quantityInput.value);
         | 
| 723 | 
            +
                        if (currentQuantity > 1) {
         | 
| 724 | 
            +
                            currentQuantity--;
         | 
| 725 | 
            +
                            quantityInput.value = currentQuantity;
         | 
| 726 | 
            +
                        }
         | 
| 727 | 
            +
                    });
         | 
| 728 | 
            +
             | 
| 729 | 
            +
                    // Add event listener to increase button
         | 
| 730 | 
            +
                    increaseBtn.addEventListener('click', function () {
         | 
| 731 | 
            +
                        let currentQuantity = parseInt(quantityInput.value);
         | 
| 732 | 
            +
                        currentQuantity++;
         | 
| 733 | 
            +
                        quantityInput.value = currentQuantity;
         | 
| 734 | 
            +
                    });
         | 
| 735 | 
             
                });
         | 
|  | |
| 736 |  | 
| 737 | 
             
                // Function to round reward points to a single digit
         | 
| 738 | 
            +
                function roundRewardPoints() {
         | 
| 739 | 
            +
                    let rewardPointsElement = document.getElementById('reward-points');
         | 
| 740 | 
            +
             | 
| 741 | 
            +
                    if (rewardPointsElement) {
         | 
| 742 | 
            +
                        let rewardPointsText = rewardPointsElement.innerText.trim();
         | 
| 743 | 
            +
                        let rewardPoints = parseFloat(rewardPointsText);
         | 
| 744 | 
            +
             | 
| 745 | 
            +
                        if (!isNaN(rewardPoints)) {
         | 
| 746 | 
            +
                            rewardPointsElement.innerText = rewardPoints.toFixed(1);
         | 
| 747 | 
            +
                        } else {
         | 
| 748 | 
            +
                            console.error("Reward points value is not a valid number:", rewardPointsText);
         | 
| 749 | 
            +
                        }
         | 
|  | |
|  | |
| 750 | 
             
                    } else {
         | 
| 751 | 
            +
                        console.error("Reward points element is missing.");
         | 
| 752 | 
             
                    }
         | 
|  | |
|  | |
| 753 | 
             
                }
         | 
| 754 | 
            +
             | 
| 755 | 
            +
                window.onload = roundRewardPoints;
         | 
| 756 | 
            +
            </script>
         | 
|  | |
|  | |
| 757 |  | 
| 758 | 
             
                <!-- Bootstrap JS -->
         | 
| 759 | 
             
                <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
         | 
