Update order.py
Browse files
order.py
CHANGED
|
@@ -29,51 +29,3 @@ def order_summary():
|
|
| 29 |
except Exception as e:
|
| 30 |
print(f"Error fetching order details: {str(e)}")
|
| 31 |
return render_template("order.html", order=None, error=str(e))
|
| 32 |
-
@order_blueprint.route("/order/items", methods=["GET"])
|
| 33 |
-
def order_items():
|
| 34 |
-
email = session.get('user_email') # Fetch logged-in user's email
|
| 35 |
-
if not email:
|
| 36 |
-
print("No user email found. Redirecting to login.")
|
| 37 |
-
return redirect(url_for("login"))
|
| 38 |
-
|
| 39 |
-
try:
|
| 40 |
-
# Fetch the most recent order for the user
|
| 41 |
-
print(f"Fetching order details for email: {email}")
|
| 42 |
-
result = sf.query(f"""
|
| 43 |
-
SELECT Id, Order_Details__c
|
| 44 |
-
FROM Order__c
|
| 45 |
-
WHERE Customer_Email__c = '{email}'
|
| 46 |
-
ORDER BY CreatedDate DESC
|
| 47 |
-
LIMIT 1
|
| 48 |
-
""")
|
| 49 |
-
|
| 50 |
-
# Check if the query was successful and print the result
|
| 51 |
-
print("Query result:", result)
|
| 52 |
-
|
| 53 |
-
order = result.get("records", [])[0] if result.get("records") else None
|
| 54 |
-
|
| 55 |
-
if not order:
|
| 56 |
-
print("No order found for the user.")
|
| 57 |
-
return render_template("order_items.html", items=None)
|
| 58 |
-
|
| 59 |
-
# Extract item names from the order details
|
| 60 |
-
item_names = []
|
| 61 |
-
if order.get("Order_Details__c"):
|
| 62 |
-
print("Found order details. Extracting item names.")
|
| 63 |
-
for line in order["Order_Details__c"].split('\n'):
|
| 64 |
-
item_parts = line.split('|')
|
| 65 |
-
if item_parts:
|
| 66 |
-
item_name = item_parts[0].strip() # Assuming the item name is the first part
|
| 67 |
-
item_names.append(item_name)
|
| 68 |
-
print(f"Extracted item: {item_name}") # Print each extracted item name
|
| 69 |
-
|
| 70 |
-
if item_names:
|
| 71 |
-
print(f"Total items extracted: {len(item_names)}")
|
| 72 |
-
else:
|
| 73 |
-
print("No items found in order details.")
|
| 74 |
-
|
| 75 |
-
return render_template("order_items.html", items=item_names)
|
| 76 |
-
|
| 77 |
-
except Exception as e:
|
| 78 |
-
print(f"Error fetching order details: {str(e)}")
|
| 79 |
-
return render_template("order_items.html", items=None, error=str(e))
|
|
|
|
| 29 |
except Exception as e:
|
| 30 |
print(f"Error fetching order details: {str(e)}")
|
| 31 |
return render_template("order.html", order=None, error=str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|