nagasurendra commited on
Commit
6307340
·
verified ·
1 Parent(s): 5618501

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -13
app.py CHANGED
@@ -68,23 +68,45 @@ def generate_coupon_code(length=10):
68
  import re
69
 
70
  import re
71
- @app.route('/customer_details')
72
  def customer_details():
73
- email = session.get('user_email') # Get logged-in user email from session
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
- # Fetch customer details using the email
76
- customer = get_customer_details_from_db(email) # Query Salesforce or your DB
 
77
 
78
- # Create a dictionary with customer details, including referral code and reward points
79
- customer_data = {
80
- 'name': customer.Name,
81
- 'email': customer.Email__c,
82
- 'phone': customer.Phone_Number__c,
83
- 'referral_code': customer.Referral__c, # Referral code
84
- 'reward_points': customer.Reward_Points__c # Reward points
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