Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -145,7 +145,7 @@ def create_modal_window():
|
|
145 |
for add_on in add_ons:
|
146 |
add_ons_html += f"""
|
147 |
<label>
|
148 |
-
<input type="checkbox" name="biryani-extra" value="{add_on['Name']}" data-price="{add_on['Price__c']}" />
|
149 |
{add_on['Name']} + ${add_on['Price__c']}
|
150 |
</label>
|
151 |
<br>
|
@@ -206,9 +206,8 @@ def modal_js():
|
|
206 |
const extras = selectedAddOns.map(extra => ({
|
207 |
name: extra.value,
|
208 |
price: parseFloat(extra.getAttribute('data-price')),
|
209 |
-
|
210 |
}));
|
211 |
-
const extrasCost = extras.reduce((total, extra) => total + (extra.price *
|
212 |
const totalCost = (price * quantity) + extrasCost;
|
213 |
// Add the item to the cart with its specific add-ons
|
214 |
cart.push({ name, price, quantity, extras, instructions, totalCost });
|
@@ -226,7 +225,7 @@ def modal_js():
|
|
226 |
const cartItemsContainer = document.getElementById('cart-items');
|
227 |
cartItemsContainer.innerHTML = "";
|
228 |
cart.forEach((item, index) => {
|
229 |
-
const extrasList = item.extras.map(extra => `${extra.name}
|
230 |
cartItemsContainer.innerHTML += `
|
231 |
<div style="border: 1px solid #ddd; padding: 10px; margin-bottom: 10px; border-radius: 8px;">
|
232 |
<h3>${item.name}</h3>
|
@@ -253,12 +252,10 @@ def modal_js():
|
|
253 |
function updateCartItem(index, type, value) {
|
254 |
if (type === 'item') {
|
255 |
cart[index].quantity = parseInt(value);
|
256 |
-
} else if (type === 'extra') {
|
257 |
-
cart[index].extras[0].quantity = parseInt(value); // Assuming one add-on for simplicity
|
258 |
}
|
259 |
const item = cart[index];
|
260 |
const price = item.price;
|
261 |
-
const extrasCost = item.extras.reduce((total, extra) => total + (extra.price *
|
262 |
item.totalCost = (price * item.quantity) + extrasCost;
|
263 |
document.getElementById(`item-${index}-total`).innerText = item.totalCost.toFixed(2);
|
264 |
updateCartTotalCost(); // Update total cost displayed
|
@@ -276,7 +273,7 @@ def modal_js():
|
|
276 |
// Reset all selected add-ons when opening a new item modal
|
277 |
function resetAddOns() {
|
278 |
const checkboxes = document.querySelectorAll('input[name="biryani-extra"]');
|
279 |
-
checkboxes.forEach(checkbox => checkbox.checked =
|
280 |
}
|
281 |
</script>
|
282 |
"""
|
|
|
145 |
for add_on in add_ons:
|
146 |
add_ons_html += f"""
|
147 |
<label>
|
148 |
+
<input type="checkbox" name="biryani-extra" value="{add_on['Name']}" data-price="{add_on['Price__c']}" checked="checked" />
|
149 |
{add_on['Name']} + ${add_on['Price__c']}
|
150 |
</label>
|
151 |
<br>
|
|
|
206 |
const extras = selectedAddOns.map(extra => ({
|
207 |
name: extra.value,
|
208 |
price: parseFloat(extra.getAttribute('data-price')),
|
|
|
209 |
}));
|
210 |
+
const extrasCost = extras.reduce((total, extra) => total + (extra.price * 1), 0); // Default quantity for add-ons set to 1
|
211 |
const totalCost = (price * quantity) + extrasCost;
|
212 |
// Add the item to the cart with its specific add-ons
|
213 |
cart.push({ name, price, quantity, extras, instructions, totalCost });
|
|
|
225 |
const cartItemsContainer = document.getElementById('cart-items');
|
226 |
cartItemsContainer.innerHTML = "";
|
227 |
cart.forEach((item, index) => {
|
228 |
+
const extrasList = item.extras.map(extra => `${extra.name} (+$${extra.price})`).join(', ');
|
229 |
cartItemsContainer.innerHTML += `
|
230 |
<div style="border: 1px solid #ddd; padding: 10px; margin-bottom: 10px; border-radius: 8px;">
|
231 |
<h3>${item.name}</h3>
|
|
|
252 |
function updateCartItem(index, type, value) {
|
253 |
if (type === 'item') {
|
254 |
cart[index].quantity = parseInt(value);
|
|
|
|
|
255 |
}
|
256 |
const item = cart[index];
|
257 |
const price = item.price;
|
258 |
+
const extrasCost = item.extras.reduce((total, extra) => total + (extra.price * 1), 0);
|
259 |
item.totalCost = (price * item.quantity) + extrasCost;
|
260 |
document.getElementById(`item-${index}-total`).innerText = item.totalCost.toFixed(2);
|
261 |
updateCartTotalCost(); // Update total cost displayed
|
|
|
273 |
// Reset all selected add-ons when opening a new item modal
|
274 |
function resetAddOns() {
|
275 |
const checkboxes = document.querySelectorAll('input[name="biryani-extra"]');
|
276 |
+
checkboxes.forEach(checkbox => checkbox.checked = true); // Set all add-ons to be checked by default
|
277 |
}
|
278 |
</script>
|
279 |
"""
|