Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -68,23 +68,45 @@ def generate_coupon_code(length=10):
|
|
| 68 |
import re
|
| 69 |
|
| 70 |
import re
|
| 71 |
-
@app.route(
|
| 72 |
def customer_details():
|
| 73 |
-
email = session.get('user_email') # Get logged-in user email
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
|
|
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
-
return render_template('customer_details.html', customer=customer_data)
|
| 88 |
@app.route("/order-history", methods=["GET"])
|
| 89 |
def order_history():
|
| 90 |
email = session.get('user_email') # Get logged-in user's email
|
|
|
|
| 68 |
import re
|
| 69 |
|
| 70 |
import re
|
| 71 |
+
@app.route("/customer_details", methods=["GET"])
|
| 72 |
def customer_details():
|
| 73 |
+
email = session.get('user_email') # Get logged-in user's email
|
| 74 |
+
|
| 75 |
+
if not email:
|
| 76 |
+
return redirect(url_for("login")) # If no email is found, redirect to login
|
| 77 |
+
|
| 78 |
+
try:
|
| 79 |
+
# Fetch customer details from Salesforce based on the email
|
| 80 |
+
customer_record = sf.query(f"""
|
| 81 |
+
SELECT Name, Email__c, Phone_Number__c, Referral__c, Reward_Points__c
|
| 82 |
+
FROM Customer_Login__c
|
| 83 |
+
WHERE Email__c = '{email}'
|
| 84 |
+
LIMIT 1
|
| 85 |
+
""")
|
| 86 |
|
| 87 |
+
# If no customer record found, handle it
|
| 88 |
+
if not customer_record.get("records"):
|
| 89 |
+
return jsonify({"success": False, "message": "Customer not found in Salesforce"})
|
| 90 |
|
| 91 |
+
# Get the customer details
|
| 92 |
+
customer = customer_record["records"][0]
|
| 93 |
+
|
| 94 |
+
# Prepare the data to return to the frontend
|
| 95 |
+
customer_data = {
|
| 96 |
+
"name": customer.get("Name", ""),
|
| 97 |
+
"email": customer.get("Email__c", ""),
|
| 98 |
+
"phone": customer.get("Phone_Number__c", ""),
|
| 99 |
+
"referral_code": customer.get("Referral__c", ""),
|
| 100 |
+
"reward_points": customer.get("Reward_Points__c", 0)
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
# Return the customer details as JSON response
|
| 104 |
+
return render_template("customer_details.html", customer=customer_data)
|
| 105 |
+
|
| 106 |
+
except Exception as e:
|
| 107 |
+
print(f"Error fetching customer details: {str(e)}")
|
| 108 |
+
return jsonify({"success": False, "message": f"Error fetching customer details: {str(e)}"})
|
| 109 |
|
|
|
|
| 110 |
@app.route("/order-history", methods=["GET"])
|
| 111 |
def order_history():
|
| 112 |
email = session.get('user_email') # Get logged-in user's email
|