Spaces:
Sleeping
Sleeping
File size: 1,943 Bytes
4c9277e 1356b75 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
document.querySelectorAll('.add-button, .food-image').forEach(item => {
item.addEventListener('click', function () {
const foodItem = this.dataset.item;
showModal(foodItem);
});
});
function showModal(foodItem) {
const modal = document.getElementById('suggestion-modal');
document.getElementById('selected-item').innerText = foodItem;
const suggestions = getSuggestions(foodItem);
const suggestionList = document.getElementById('suggestion-list');
suggestionList.innerHTML = suggestions.map(item => `<li>${item}</li>`).join('');
modal.style.display = 'flex';
document.querySelector('.close-button').addEventListener('click', () => {
modal.style.display = 'none';
});
document.getElementById('add-to-cart-button').addEventListener('click', () => {
addToCart(foodItem, suggestions);
modal.style.display = 'none';
});
}
function getSuggestions(foodItem) {
const suggestionData = {
'Veg Samosa': ['Green Chutney', 'Masala Tea'],
'Onion Pakoda': ['Tamarind Sauce', 'Hot Tea'],
// Add more combinations here
};
return suggestionData[foodItem] || [];
}
let cart = [];
function addToCart(foodItem, suggestions) {
const quantity = document.getElementById('quantity').value;
cart.push({ foodItem, quantity, suggestions });
alert(`Added to cart: ${foodItem} (x${quantity})`);
console.log('Cart:', cart);
}
function addToCart(itemName) {
const quantity = document.getElementById(`quantity-${itemName}`).value;
fetch("/add_to_cart", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ name: itemName, quantity: quantity }),
})
.then((response) => response.json())
.then((data) => {
alert(data.message);
// Optionally update cart count in the UI
})
.catch((error) => {
console.error("Error:", error);
});
}
|