Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -150,6 +150,7 @@ def modal_js():
|
|
150 |
modal_script = """
|
151 |
<script>
|
152 |
let cart = [];
|
|
|
153 |
|
154 |
function openModal(name, image2, description, price) {
|
155 |
const modal = document.getElementById('modal');
|
@@ -182,8 +183,12 @@ def modal_js():
|
|
182 |
}));
|
183 |
const extrasCost = extras.reduce((total, extra) => total + extra.price, 0);
|
184 |
const totalCost = (price + extrasCost) * quantity;
|
|
|
|
|
185 |
cart.push({ name, price, quantity, extras, instructions, totalCost });
|
|
|
186 |
updateCartButton();
|
|
|
187 |
closeModal();
|
188 |
}
|
189 |
|
@@ -196,6 +201,7 @@ def modal_js():
|
|
196 |
const cartModal = document.getElementById('cart-modal');
|
197 |
const cartItemsContainer = document.getElementById('cart-items');
|
198 |
cartItemsContainer.innerHTML = "";
|
|
|
199 |
cart.forEach((item, index) => {
|
200 |
const extrasList = item.extras.map(extra => `${extra.name} (+$${extra.price.toFixed(2)})`).join(', ');
|
201 |
cartItemsContainer.innerHTML += `
|
@@ -209,6 +215,7 @@ def modal_js():
|
|
209 |
</div>
|
210 |
`;
|
211 |
});
|
|
|
212 |
cartModal.style.display = 'block';
|
213 |
}
|
214 |
|
@@ -217,11 +224,18 @@ def modal_js():
|
|
217 |
}
|
218 |
|
219 |
function removeFromCart(index) {
|
|
|
220 |
cart.splice(index, 1);
|
221 |
updateCartButton();
|
|
|
222 |
openCartModal();
|
223 |
}
|
224 |
|
|
|
|
|
|
|
|
|
|
|
225 |
function proceedToCheckout() {
|
226 |
alert("Proceeding to checkout...");
|
227 |
}
|
@@ -256,12 +270,8 @@ with gr.Blocks() as app:
|
|
256 |
with gr.Column():
|
257 |
preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
|
258 |
menu_output = gr.HTML()
|
259 |
-
gr.HTML(""
|
260 |
-
|
261 |
-
View Cart
|
262 |
-
</div>
|
263 |
-
""")
|
264 |
-
gr.HTML("<div id='cart-modal' style='display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: white; z-index: 1000; overflow-y: auto;'><div style='padding: 20px;'><div style='text-align: right;'><button onclick='closeCartModal()' style='background: none; border: none; font-size: 24px; cursor: pointer;'>×</button></div><h1>Your Cart</h1><div id='cart-items'></div><button style='background: #ff5722; color: white; padding: 10px 20px; border-radius: 5px; border: none; cursor: pointer;' onclick='proceedToCheckout()'>Proceed to Checkout</button></div></div>")
|
265 |
gr.HTML(create_modal_window())
|
266 |
gr.HTML(modal_js())
|
267 |
|
|
|
150 |
modal_script = """
|
151 |
<script>
|
152 |
let cart = [];
|
153 |
+
let totalCartCost = 0;
|
154 |
|
155 |
function openModal(name, image2, description, price) {
|
156 |
const modal = document.getElementById('modal');
|
|
|
183 |
}));
|
184 |
const extrasCost = extras.reduce((total, extra) => total + extra.price, 0);
|
185 |
const totalCost = (price + extrasCost) * quantity;
|
186 |
+
|
187 |
+
// Add the item to the cart
|
188 |
cart.push({ name, price, quantity, extras, instructions, totalCost });
|
189 |
+
totalCartCost += totalCost; // Update the total cost of the cart
|
190 |
updateCartButton();
|
191 |
+
updateCartTotalCost(); // Update total cost displayed
|
192 |
closeModal();
|
193 |
}
|
194 |
|
|
|
201 |
const cartModal = document.getElementById('cart-modal');
|
202 |
const cartItemsContainer = document.getElementById('cart-items');
|
203 |
cartItemsContainer.innerHTML = "";
|
204 |
+
|
205 |
cart.forEach((item, index) => {
|
206 |
const extrasList = item.extras.map(extra => `${extra.name} (+$${extra.price.toFixed(2)})`).join(', ');
|
207 |
cartItemsContainer.innerHTML += `
|
|
|
215 |
</div>
|
216 |
`;
|
217 |
});
|
218 |
+
|
219 |
cartModal.style.display = 'block';
|
220 |
}
|
221 |
|
|
|
224 |
}
|
225 |
|
226 |
function removeFromCart(index) {
|
227 |
+
totalCartCost -= cart[index].totalCost; // Deduct the cost of the removed item from total cost
|
228 |
cart.splice(index, 1);
|
229 |
updateCartButton();
|
230 |
+
updateCartTotalCost(); // Update total cost displayed
|
231 |
openCartModal();
|
232 |
}
|
233 |
|
234 |
+
function updateCartTotalCost() {
|
235 |
+
const totalCostElement = document.getElementById('cart-total-cost');
|
236 |
+
totalCostElement.innerText = `Total Cart Cost: $${totalCartCost.toFixed(2)}`;
|
237 |
+
}
|
238 |
+
|
239 |
function proceedToCheckout() {
|
240 |
alert("Proceeding to checkout...");
|
241 |
}
|
|
|
270 |
with gr.Column():
|
271 |
preference = gr.Radio(choices=["All", "Veg", "Non-Veg"], label="Filter Preference", value="All")
|
272 |
menu_output = gr.HTML()
|
273 |
+
gr.HTML("<div id='cart-button' style='position: fixed; top: 20px; right: 20px; background: #28a745; color: white; padding: 10px 20px; border-radius: 30px; cursor: pointer; z-index: 1000;' onclick='openCartModal()'>View Cart</div>")
|
274 |
+
gr.HTML("<div id='cart-modal' style='display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: white; z-index: 1000; overflow-y: auto;'><div style='padding: 20px;'><div style='text-align: right;'><button onclick='closeCartModal()' style='background: none; border: none; font-size: 24px; cursor: pointer;'>×</button></div><h1>Your Cart</h1><div id='cart-items'></div><p id='cart-total-cost' style='font-size: 1.2em; font-weight: bold;'>Total Cart Cost: $0.00</p><button style='background: #ff5722; color: white; padding: 10px 20px; border-radius: 5px; border: none; cursor: pointer;' onclick='proceedToCheckout()'>Proceed to Checkout</button></div></div>")
|
|
|
|
|
|
|
|
|
275 |
gr.HTML(create_modal_window())
|
276 |
gr.HTML(modal_js())
|
277 |
|