Update app.py
Browse files
app.py
CHANGED
@@ -190,6 +190,54 @@ def reward_status():
|
|
190 |
next_tier=next_tier,
|
191 |
tiers=tiers
|
192 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
|
194 |
@app.route("/logout")
|
195 |
def logout():
|
|
|
190 |
next_tier=next_tier,
|
191 |
tiers=tiers
|
192 |
)
|
193 |
+
@app.route("/order/items", methods=["GET"])
|
194 |
+
def order_items():
|
195 |
+
email = session.get('user_email') # Fetch logged-in user's email
|
196 |
+
if not email:
|
197 |
+
print("No user email found. Redirecting to login.")
|
198 |
+
return redirect(url_for("login"))
|
199 |
+
|
200 |
+
try:
|
201 |
+
# Fetch the most recent order for the user
|
202 |
+
print(f"Fetching order details for email: {email}")
|
203 |
+
result = sf.query(f"""
|
204 |
+
SELECT Id, Order_Details__c
|
205 |
+
FROM Order__c
|
206 |
+
WHERE Customer_Email__c = '{email}'
|
207 |
+
ORDER BY CreatedDate DESC
|
208 |
+
LIMIT 1
|
209 |
+
""")
|
210 |
+
|
211 |
+
# Check if the query was successful and print the result
|
212 |
+
print("Query result:", result)
|
213 |
+
|
214 |
+
order = result.get("records", [])[0] if result.get("records") else None
|
215 |
+
|
216 |
+
if not order:
|
217 |
+
print("No order found for the user.")
|
218 |
+
return render_template("order_items.html", items=None)
|
219 |
+
|
220 |
+
# Extract item names from the order details
|
221 |
+
item_names = []
|
222 |
+
if order.get("Order_Details__c"):
|
223 |
+
print("Found order details. Extracting item names.")
|
224 |
+
for line in order["Order_Details__c"].split('\n'):
|
225 |
+
item_parts = line.split('|')
|
226 |
+
if item_parts:
|
227 |
+
item_name = item_parts[0].strip() # Assuming the item name is the first part
|
228 |
+
item_names.append(item_name)
|
229 |
+
print(f"Extracted item: {item_name}") # Print each extracted item name
|
230 |
+
|
231 |
+
if item_names:
|
232 |
+
print(f"Total items extracted: {len(item_names)}")
|
233 |
+
else:
|
234 |
+
print("No items found in order details.")
|
235 |
+
|
236 |
+
return render_template("order_items.html", items=item_names)
|
237 |
+
|
238 |
+
except Exception as e:
|
239 |
+
print(f"Error fetching order details: {str(e)}")
|
240 |
+
return render_template("order_items.html", items=None, error=str(e))
|
241 |
|
242 |
@app.route("/logout")
|
243 |
def logout():
|