Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -150,24 +150,37 @@ def modal_js():
|
|
150 |
modal_script = """
|
151 |
<script>
|
152 |
let cart = [];
|
153 |
-
function
|
154 |
-
const
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
}
|
|
|
168 |
function closeModal() {
|
169 |
-
document.getElementById('modal').style.display = 'none';
|
170 |
}
|
|
|
171 |
function addToCart() {
|
172 |
const name = document.getElementById('modal-name').innerText;
|
173 |
const price = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
|
@@ -179,43 +192,33 @@ def modal_js():
|
|
179 |
}));
|
180 |
const extrasCost = extras.reduce((total, extra) => total + extra.price, 0);
|
181 |
const totalCost = (price + extrasCost) * quantity;
|
|
|
|
|
182 |
cart.push({ name, price, quantity, extras, instructions, totalCost });
|
|
|
|
|
183 |
updateCartButton();
|
|
|
|
|
184 |
closeModal();
|
185 |
}
|
|
|
186 |
function updateCartButton() {
|
|
|
187 |
const cartButton = document.getElementById('cart-button');
|
188 |
-
cartButton.innerText = `View Cart (${cart.length} items)`;
|
189 |
const cartButtonTop = document.getElementById('cart-button-top');
|
|
|
|
|
190 |
cartButtonTop.innerText = `View Cart (${cart.length} items)`;
|
191 |
}
|
192 |
-
|
193 |
-
const cartModal = document.getElementById('cart-modal');
|
194 |
-
const cartItemsContainer = document.getElementById('cart-items');
|
195 |
-
cartItemsContainer.innerHTML = "";
|
196 |
-
cart.forEach((item, index) => {
|
197 |
-
const extrasList = item.extras.map(extra => `${extra.name} (+$${extra.price.toFixed(2)})`).join(', ');
|
198 |
-
cartItemsContainer.innerHTML += `
|
199 |
-
<div style="border: 1px solid #ddd; padding: 10px; margin-bottom: 10px; border-radius: 8px;">
|
200 |
-
<h3>${item.name}</h3>
|
201 |
-
<p>Quantity: ${item.quantity}</p>
|
202 |
-
<p>Extras: ${extrasList || 'None'}</p>
|
203 |
-
<p>Special Instructions: ${item.instructions || 'None'}</p>
|
204 |
-
<p>Total Cost: $${item.totalCost.toFixed(2)}</p>
|
205 |
-
<button onclick="removeFromCart(${index})" style="color: red;">Remove</button>
|
206 |
-
</div>
|
207 |
-
`;
|
208 |
-
});
|
209 |
-
cartModal.style.display = 'block';
|
210 |
-
}
|
211 |
-
function closeCartModal() {
|
212 |
-
document.getElementById('cart-modal').style.display = 'none';
|
213 |
-
}
|
214 |
function removeFromCart(index) {
|
|
|
215 |
cart.splice(index, 1);
|
216 |
updateCartButton();
|
217 |
-
openCartModal();
|
218 |
}
|
|
|
219 |
function proceedToCheckout() {
|
220 |
alert("Proceeding to checkout...");
|
221 |
}
|
|
|
150 |
modal_script = """
|
151 |
<script>
|
152 |
let cart = [];
|
153 |
+
function openCartModal() {
|
154 |
+
const cartModal = document.getElementById('cart-modal');
|
155 |
+
const cartItemsContainer = document.getElementById('cart-items');
|
156 |
+
|
157 |
+
// Empty the current cart content and update with the latest cart items
|
158 |
+
cartItemsContainer.innerHTML = "";
|
159 |
+
|
160 |
+
// Loop through the cart and add it to the modal
|
161 |
+
cart.forEach((item, index) => {
|
162 |
+
const extrasList = item.extras.map(extra => `${extra.name} (+$${extra.price.toFixed(2)})`).join(', ');
|
163 |
+
cartItemsContainer.innerHTML += `
|
164 |
+
<div style="border: 1px solid #ddd; padding: 10px; margin-bottom: 10px; border-radius: 8px;">
|
165 |
+
<h3>${item.name}</h3>
|
166 |
+
<p>Quantity: ${item.quantity}</p>
|
167 |
+
<p>Extras: ${extrasList || 'None'}</p>
|
168 |
+
<p>Special Instructions: ${item.instructions || 'None'}</p>
|
169 |
+
<p>Total Cost: $${item.totalCost.toFixed(2)}</p>
|
170 |
+
<button onclick="removeFromCart(${index})" style="color: red;">Remove</button>
|
171 |
+
</div>
|
172 |
+
`;
|
173 |
+
});
|
174 |
+
|
175 |
+
// Ensure modal is visible
|
176 |
+
cartModal.style.display = 'block';
|
177 |
+
cartModal.style.zIndex = 10000; // Ensure it's above other elements
|
178 |
}
|
179 |
+
|
180 |
function closeModal() {
|
181 |
+
document.getElementById('cart-modal').style.display = 'none';
|
182 |
}
|
183 |
+
|
184 |
function addToCart() {
|
185 |
const name = document.getElementById('modal-name').innerText;
|
186 |
const price = parseFloat(document.getElementById('modal-price').innerText.replace('$', ''));
|
|
|
192 |
}));
|
193 |
const extrasCost = extras.reduce((total, extra) => total + extra.price, 0);
|
194 |
const totalCost = (price + extrasCost) * quantity;
|
195 |
+
|
196 |
+
// Push the item to the cart
|
197 |
cart.push({ name, price, quantity, extras, instructions, totalCost });
|
198 |
+
|
199 |
+
// Update the cart button text with the number of items
|
200 |
updateCartButton();
|
201 |
+
|
202 |
+
// Close the modal after adding the item
|
203 |
closeModal();
|
204 |
}
|
205 |
+
|
206 |
function updateCartButton() {
|
207 |
+
// Update both buttons to show the number of items in the cart
|
208 |
const cartButton = document.getElementById('cart-button');
|
|
|
209 |
const cartButtonTop = document.getElementById('cart-button-top');
|
210 |
+
|
211 |
+
cartButton.innerText = `View Cart (${cart.length} items)`;
|
212 |
cartButtonTop.innerText = `View Cart (${cart.length} items)`;
|
213 |
}
|
214 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
function removeFromCart(index) {
|
216 |
+
// Remove an item from the cart and update the cart button
|
217 |
cart.splice(index, 1);
|
218 |
updateCartButton();
|
219 |
+
openCartModal(); // Refresh the cart modal after removing an item
|
220 |
}
|
221 |
+
|
222 |
function proceedToCheckout() {
|
223 |
alert("Proceeding to checkout...");
|
224 |
}
|