Spaces:
Sleeping
Sleeping
Create order_history.py
Browse files- components/order_history.py +30 -0
components/order_history.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from utils.excel_operations import read_excel, write_excel
|
3 |
+
from utils.state_management import state
|
4 |
+
|
5 |
+
def order_history_page():
|
6 |
+
def fetch_order_history(email):
|
7 |
+
orders = read_excel('data/orders.xlsx')
|
8 |
+
user_orders = [order for order in orders if order["Customer Email"] == email]
|
9 |
+
return user_orders
|
10 |
+
|
11 |
+
def reorder(order_id):
|
12 |
+
orders = read_excel('data/orders.xlsx')
|
13 |
+
order = next((o for o in orders if o["Order ID"] == order_id), None)
|
14 |
+
if order:
|
15 |
+
state["cart"] = order["Items"]
|
16 |
+
return "Reordered items added to cart!"
|
17 |
+
return "Order not found!"
|
18 |
+
|
19 |
+
with gr.Group():
|
20 |
+
gr.Markdown("### Order History")
|
21 |
+
if state.get("user"):
|
22 |
+
email = state["user"]["Email"]
|
23 |
+
order_history = fetch_order_history(email)
|
24 |
+
for order in order_history:
|
25 |
+
gr.Text(f"Order ID: {order['Order ID']}")
|
26 |
+
gr.Text(f"Items: {', '.join([item['Item'] for item in order['Items']])}")
|
27 |
+
gr.Text(f"Total Cost: {order['Total Cost']} ₹")
|
28 |
+
gr.Button("Reorder").click(reorder, inputs=[order["Order ID"]], outputs="Status")
|
29 |
+
else:
|
30 |
+
gr.Markdown("Please log in to view your order history.")
|