nagasurendra commited on
Commit
8310d66
·
verified ·
1 Parent(s): f9cbd15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -11
app.py CHANGED
@@ -1256,9 +1256,23 @@ def order_summary():
1256
  return redirect(url_for("login"))
1257
 
1258
  try:
1259
- # Fetch the most recent order for the user (replace this with your Salesforce or database query)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1260
  result = sf.query(f"""
1261
- SELECT Id, Customer_Name__c, Customer_Email__c, Phone__c, Total_Amount__c, Order_Details__c, Order_Status__c, Discount__c, Total_Bill__c
1262
  FROM Order__c
1263
  WHERE Customer_Email__c = '{email}'
1264
  ORDER BY CreatedDate DESC
@@ -1269,9 +1283,13 @@ def order_summary():
1269
  if not order:
1270
  return render_template("order.html", order=None)
1271
 
1272
- # Retrieve the phone number from the order's customer (ensure it's correctly mapped)
1273
- customer_phone = order['Phone__c'] # Assuming 'Phone__c' is the field with the phone number
1274
- print(f"Customer phone number retrieved: {customer_phone}") # Log the phone number for debugging
 
 
 
 
1275
 
1276
  # Format the order details for WhatsApp
1277
  order_details = f"Order Summary for {order['Customer_Name__c']}:\n\n"
@@ -1283,10 +1301,7 @@ def order_summary():
1283
 
1284
  # Ensure the phone number is in the correct format for WhatsApp (with the 'whatsapp:' prefix)
1285
  if not customer_phone.startswith('whatsapp:'):
1286
- customer_phone = f'whatsapp:+{customer_phone}'
1287
-
1288
- # Log the final phone number before sending the message
1289
- print(f"Final phone number for message: {customer_phone}")
1290
 
1291
  # Send the order details via WhatsApp
1292
  send_whatsapp_order(customer_phone, order_details)
@@ -1297,8 +1312,6 @@ def order_summary():
1297
  return render_template("order.html", order=None, error=str(e))
1298
 
1299
 
1300
-
1301
-
1302
  import smtplib
1303
  from email.mime.multipart import MIMEMultipart
1304
  from email.mime.text import MIMEText
 
1256
  return redirect(url_for("login"))
1257
 
1258
  try:
1259
+ # Fetch customer details from Salesforce based on the email
1260
+ customer_record = sf.query(f"""
1261
+ SELECT Id, Name, Email__c, Phone_Number__c, Referral__c, Reward_Points__c
1262
+ FROM Customer_Login__c
1263
+ WHERE Email__c = '{email}'
1264
+ LIMIT 1
1265
+ """)
1266
+
1267
+ if not customer_record.get("records"):
1268
+ flash("Customer not found", "danger")
1269
+ return redirect(url_for("login"))
1270
+
1271
+ customer = customer_record["records"][0]
1272
+
1273
+ # Fetch the most recent order for the user (this is your order query)
1274
  result = sf.query(f"""
1275
+ SELECT Id, Customer_Name__c, Customer_Email__c, Total_Amount__c, Order_Details__c, Order_Status__c, Discount__c, Total_Bill__c
1276
  FROM Order__c
1277
  WHERE Customer_Email__c = '{email}'
1278
  ORDER BY CreatedDate DESC
 
1283
  if not order:
1284
  return render_template("order.html", order=None)
1285
 
1286
+ # Retrieve the phone number from the Customer_Login__c record
1287
+ customer_phone = customer.get('Phone_Number__c', None)
1288
+ if not customer_phone:
1289
+ flash("Phone number not found for this customer", "danger")
1290
+ return redirect(url_for("login"))
1291
+
1292
+ print(f"Customer phone number: {customer_phone}") # Log the phone number for debugging
1293
 
1294
  # Format the order details for WhatsApp
1295
  order_details = f"Order Summary for {order['Customer_Name__c']}:\n\n"
 
1301
 
1302
  # Ensure the phone number is in the correct format for WhatsApp (with the 'whatsapp:' prefix)
1303
  if not customer_phone.startswith('whatsapp:'):
1304
+ customer_phone = f'whatsapp:+{customer_phone}' # Add country code if not present
 
 
 
1305
 
1306
  # Send the order details via WhatsApp
1307
  send_whatsapp_order(customer_phone, order_details)
 
1312
  return render_template("order.html", order=None, error=str(e))
1313
 
1314
 
 
 
1315
  import smtplib
1316
  from email.mime.multipart import MIMEMultipart
1317
  from email.mime.text import MIMEText