Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -48,51 +48,27 @@ def generate_coupon_code(length=10):
|
|
48 |
"""Generates a random alphanumeric coupon code"""
|
49 |
characters = string.ascii_uppercase + string.digits # A-Z, 0-9
|
50 |
return ''.join(random.choice(characters) for _ in range(length))
|
51 |
-
from flask import render_template
|
52 |
-
from simple_salesforce import Salesforce
|
53 |
-
import json
|
54 |
|
55 |
-
@app.route("/order-history")
|
56 |
-
def order_history():
|
57 |
-
email = session.get('user_email') # Get the logged-in user's email
|
58 |
|
|
|
|
|
|
|
59 |
if not email:
|
60 |
-
return redirect(url_for("login"))
|
61 |
|
62 |
try:
|
63 |
-
#
|
64 |
-
email = email.strip().lower()
|
65 |
-
|
66 |
-
# Log the email to check if it's being retrieved properly
|
67 |
-
print(f"Fetching orders for email: {email}")
|
68 |
-
|
69 |
-
# Fetch order records for the logged-in user
|
70 |
result = sf.query(f"""
|
71 |
-
SELECT Id,
|
|
|
72 |
FROM Order__c
|
73 |
-
WHERE
|
74 |
ORDER BY CreatedDate DESC
|
75 |
-
LIMIT 5
|
76 |
""")
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
orders = result.get("records", []) # Get the order records (max 5)
|
81 |
-
|
82 |
-
# Check if orders are returned and log them
|
83 |
-
if orders:
|
84 |
-
print(f"Found {len(orders)} orders for email {email}.")
|
85 |
-
else:
|
86 |
-
print(f"No orders found for email {email}.")
|
87 |
-
|
88 |
-
# Process the order details to split each line into individual items
|
89 |
-
for order in orders:
|
90 |
-
if order.get('Order_Details__c'):
|
91 |
-
order['items'] = order['Order_Details__c'].split('\n') # Split the order details into lines/items
|
92 |
-
else:
|
93 |
-
order['items'] = [] # If no details, set items to empty list
|
94 |
|
95 |
-
return render_template("order_history.html", orders=orders)
|
96 |
|
97 |
except Exception as e:
|
98 |
print(f"Error fetching order history: {str(e)}")
|
|
|
48 |
"""Generates a random alphanumeric coupon code"""
|
49 |
characters = string.ascii_uppercase + string.digits # A-Z, 0-9
|
50 |
return ''.join(random.choice(characters) for _ in range(length))
|
|
|
|
|
|
|
51 |
|
|
|
|
|
|
|
52 |
|
53 |
+
@app.route("/order-history", methods=["GET"])
|
54 |
+
def order_history():
|
55 |
+
email = session.get('user_email') # Get logged-in user's email
|
56 |
if not email:
|
57 |
+
return redirect(url_for("login"))
|
58 |
|
59 |
try:
|
60 |
+
# Fetch past orders for the user
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
result = sf.query(f"""
|
62 |
+
SELECT Id, Customer_Name__c, Customer_Email__c, Total_Amount__c,
|
63 |
+
Order_Details__c, Order_Status__c, Discount__c, Total_Bill__c, CreatedDate
|
64 |
FROM Order__c
|
65 |
+
WHERE Customer_Email__c = '{email}'
|
66 |
ORDER BY CreatedDate DESC
|
|
|
67 |
""")
|
68 |
|
69 |
+
orders = result.get("records", []) # Fetch all orders
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
+
return render_template("order_history.html", orders=orders)
|
72 |
|
73 |
except Exception as e:
|
74 |
print(f"Error fetching order history: {str(e)}")
|