Spaces:
Sleeping
Sleeping
Create cart.py
Browse files- components/cart.py +19 -0
components/cart.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
cart = [] # Store all cart items
|
| 2 |
+
|
| 3 |
+
def add_to_cart(dish_name, spice_level, extras, instructions, quantity, menu_data):
|
| 4 |
+
"""Add selected item with options to the cart."""
|
| 5 |
+
dish = menu_data[menu_data['Dish Name'] == dish_name].iloc[0]
|
| 6 |
+
price = dish['Price']
|
| 7 |
+
extras_cost = sum([float(extra.split('+ $')[-1]) for extra in extras]) if extras else 0
|
| 8 |
+
total_price = (price + extras_cost) * quantity
|
| 9 |
+
|
| 10 |
+
# Add to cart
|
| 11 |
+
cart.append({
|
| 12 |
+
"Dish": dish_name,
|
| 13 |
+
"Spice Level": spice_level,
|
| 14 |
+
"Extras": ", ".join(extras) if extras else "None",
|
| 15 |
+
"Instructions": instructions,
|
| 16 |
+
"Quantity": quantity,
|
| 17 |
+
"Price": f"${total_price:.2f}"
|
| 18 |
+
})
|
| 19 |
+
return cart
|