Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -90,6 +90,15 @@ def app():
|
|
| 90 |
modal_and_cart_js = """
|
| 91 |
<script>
|
| 92 |
let cart = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
function openModal(name, image, description, price) {
|
| 95 |
document.getElementById('modal').style.display = 'block';
|
|
@@ -111,29 +120,24 @@ def app():
|
|
| 111 |
const instructions = document.getElementById('special-instructions').value;
|
| 112 |
const extras = Array.from(document.querySelectorAll('input[name="biryani-extra"]:checked')).map(extra => extra.value);
|
| 113 |
|
| 114 |
-
const
|
| 115 |
-
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
headers: { "Content-Type": "application/json" },
|
| 120 |
-
body: JSON.stringify(cart)
|
| 121 |
-
});
|
| 122 |
|
| 123 |
alert(`${name} added to cart!`);
|
| 124 |
-
closeModal();
|
| 125 |
updateCartDisplay();
|
|
|
|
| 126 |
}
|
| 127 |
|
| 128 |
function updateCartDisplay() {
|
| 129 |
let totalBill = 0;
|
| 130 |
let cartHTML = "<h3>Your Cart:</h3><ul>";
|
| 131 |
cart.forEach(item => {
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
let extras = item.extras.join(', ');
|
| 136 |
-
cartHTML += `<li>${item.name} (x${item.quantity}, Spice: ${item.spiceLevel}, Extras: ${extras}, Instructions: ${item.instructions}) - $${itemTotal.toFixed(2)}</li>`;
|
| 137 |
});
|
| 138 |
cartHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
|
| 139 |
document.getElementById('floating-cart').innerHTML = cartHTML;
|
|
@@ -152,21 +156,21 @@ def app():
|
|
| 152 |
<p id="modal-description"></p>
|
| 153 |
<p id="modal-price"></p>
|
| 154 |
<!-- Spice Levels -->
|
| 155 |
-
<label for="spice-level"
|
| 156 |
<div id="spice-level-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
|
| 157 |
-
<label><input type="radio" name="spice-level" value="American Mild"
|
| 158 |
-
<label><input type="radio" name="spice-level" value="American Medium"
|
| 159 |
-
<label><input type="radio" name="spice-level" value="American Spicy"
|
| 160 |
-
<label><input type="radio" name="spice-level" value="Indian Mild"
|
| 161 |
-
<label><input type="radio" name="spice-level" value="Indian Medium"
|
| 162 |
-
<label><input type="radio" name="spice-level" value="Indian Very Spicy"
|
| 163 |
</div>
|
| 164 |
<!-- Biryani Extras -->
|
| 165 |
-
<label for="biryani-extras"
|
| 166 |
<div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
|
| 167 |
<label><input type="checkbox" name="biryani-extra" value="Extra Raitha 4oz" /> Extra Raitha 4oz + $1.00</label>
|
| 168 |
<label><input type="checkbox" name="biryani-extra" value="Extra Raitha 8oz" /> Extra Raitha 8oz + $2.00</label>
|
| 169 |
-
<label><input type="checkbox" name="biryani-extra" value="Extra Salan 4oz" /> Extra Salan 4oz + $1.00</label
|
| 170 |
<label><input type="checkbox" name="biryani-extra" value="Extra Salan 8oz" /> Extra Salan 8oz + $2.00</label>
|
| 171 |
<label><input type="checkbox" name="biryani-extra" value="Extra Onion" /> Extra Onion + $1.00</label>
|
| 172 |
<label><input type="checkbox" name="biryani-extra" value="Extra Onion & Lemon" /> Extra Onion & Lemon + $2.00</label>
|
|
|
|
| 90 |
modal_and_cart_js = """
|
| 91 |
<script>
|
| 92 |
let cart = [];
|
| 93 |
+
const extrasPrices = {
|
| 94 |
+
"Extra Raitha 4oz": 1,
|
| 95 |
+
"Extra Raitha 8oz": 2,
|
| 96 |
+
"Extra Salan 4oz": 1,
|
| 97 |
+
"Extra Salan 8oz": 2,
|
| 98 |
+
"Extra Onion": 1,
|
| 99 |
+
"Extra Onion & Lemon": 2,
|
| 100 |
+
"Extra Fried Onion 4oz": 2
|
| 101 |
+
};
|
| 102 |
|
| 103 |
function openModal(name, image, description, price) {
|
| 104 |
document.getElementById('modal').style.display = 'block';
|
|
|
|
| 120 |
const instructions = document.getElementById('special-instructions').value;
|
| 121 |
const extras = Array.from(document.querySelectorAll('input[name="biryani-extra"]:checked')).map(extra => extra.value);
|
| 122 |
|
| 123 |
+
const extrasCost = extras.reduce((sum, extra) => sum + (extrasPrices[extra] || 0), 0);
|
| 124 |
+
const itemTotal = (parseFloat(price.replace('$', '')) + extrasCost) * quantity;
|
| 125 |
|
| 126 |
+
const cartItem = { name, price, spiceLevel, quantity, instructions, extras, itemTotal };
|
| 127 |
+
cart.push(cartItem);
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
alert(`${name} added to cart!`);
|
|
|
|
| 130 |
updateCartDisplay();
|
| 131 |
+
closeModal();
|
| 132 |
}
|
| 133 |
|
| 134 |
function updateCartDisplay() {
|
| 135 |
let totalBill = 0;
|
| 136 |
let cartHTML = "<h3>Your Cart:</h3><ul>";
|
| 137 |
cart.forEach(item => {
|
| 138 |
+
totalBill += item.itemTotal;
|
| 139 |
+
const extras = item.extras.join(', ');
|
| 140 |
+
cartHTML += `<li>${item.name} (x${item.quantity}, Spice: ${item.spiceLevel}, Extras: ${extras}, Instructions: ${item.instructions}) - $${item.itemTotal.toFixed(2)}</li>`;
|
|
|
|
|
|
|
| 141 |
});
|
| 142 |
cartHTML += `</ul><p><strong>Total Bill: $${totalBill.toFixed(2)}</strong></p>`;
|
| 143 |
document.getElementById('floating-cart').innerHTML = cartHTML;
|
|
|
|
| 156 |
<p id="modal-description"></p>
|
| 157 |
<p id="modal-price"></p>
|
| 158 |
<!-- Spice Levels -->
|
| 159 |
+
<label for="spice-level">Choose a Spice Level (Required):</label>
|
| 160 |
<div id="spice-level-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
|
| 161 |
+
<label><input type="radio" name="spice-level" value="American Mild" /> American Mild</label>
|
| 162 |
+
<label><input type="radio" name="spice-level" value="American Medium" /> American Medium</label>
|
| 163 |
+
<label><input type="radio" name="spice-level" value="American Spicy" /> American Spicy</label>
|
| 164 |
+
<label><input type="radio" name="spice-level" value="Indian Mild" /> Indian Mild</label>
|
| 165 |
+
<label><input type="radio" name="spice-level" value="Indian Medium" /> Indian Medium</label>
|
| 166 |
+
<label><input type="radio" name="spice-level" value="Indian Very Spicy" /> Indian Very Spicy</label>
|
| 167 |
</div>
|
| 168 |
<!-- Biryani Extras -->
|
| 169 |
+
<label for="biryani-extras">Biryani Extras (Optional - Choose as many as you like):</label>
|
| 170 |
<div id="biryani-extras-options" style="display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
|
| 171 |
<label><input type="checkbox" name="biryani-extra" value="Extra Raitha 4oz" /> Extra Raitha 4oz + $1.00</label>
|
| 172 |
<label><input type="checkbox" name="biryani-extra" value="Extra Raitha 8oz" /> Extra Raitha 8oz + $2.00</label>
|
| 173 |
+
<label><input type="checkbox" name="biryani-extra" value="Extra Salan 4oz" /> Extra Salan 4oz + $1.00</label>
|
| 174 |
<label><input type="checkbox" name="biryani-extra" value="Extra Salan 8oz" /> Extra Salan 8oz + $2.00</label>
|
| 175 |
<label><input type="checkbox" name="biryani-extra" value="Extra Onion" /> Extra Onion + $1.00</label>
|
| 176 |
<label><input type="checkbox" name="biryani-extra" value="Extra Onion & Lemon" /> Extra Onion & Lemon + $2.00</label>
|