nagasurendra commited on
Commit
7780e22
·
verified ·
1 Parent(s): a7a52a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -409,12 +409,16 @@ def checkout():
409
 
410
  # Fetch the current Reward_Points__c for the user
411
  customer_record = sf.query(f"""
412
- SELECT Reward_Points__c FROM Customer_Login__c
413
  WHERE Email__c = '{email}'
414
  """)
415
  customer = customer_record.get("records", [])[0] if customer_record else None
416
 
417
  if customer:
 
 
 
 
418
  # Calculate 10% of the subtotal
419
  reward_points_to_add = total_price * 0.10
420
 
@@ -422,9 +426,12 @@ def checkout():
422
  new_reward_points = customer['Reward_Points__c'] + reward_points_to_add if customer.get('Reward_Points__c') else reward_points_to_add
423
 
424
  # Update the Reward_Points__c field in Salesforce
425
- sf.Customer_Login__c.update(customer['Id'], {
426
- "Reward_Points__c": new_reward_points
427
- })
 
 
 
428
 
429
  # Clear the cart after placing the order
430
  for item in cart_items:
 
409
 
410
  # Fetch the current Reward_Points__c for the user
411
  customer_record = sf.query(f"""
412
+ SELECT Id, Reward_Points__c FROM Customer_Login__c
413
  WHERE Email__c = '{email}'
414
  """)
415
  customer = customer_record.get("records", [])[0] if customer_record else None
416
 
417
  if customer:
418
+ # Check if 'Id' exists in the customer record before attempting to update
419
+ if 'Id' not in customer:
420
+ return jsonify({"success": False, "message": "'Id' not found for customer record."})
421
+
422
  # Calculate 10% of the subtotal
423
  reward_points_to_add = total_price * 0.10
424
 
 
426
  new_reward_points = customer['Reward_Points__c'] + reward_points_to_add if customer.get('Reward_Points__c') else reward_points_to_add
427
 
428
  # Update the Reward_Points__c field in Salesforce
429
+ try:
430
+ sf.Customer_Login__c.update(customer['Id'], {
431
+ "Reward_Points__c": new_reward_points
432
+ })
433
+ except Exception as update_error:
434
+ return jsonify({"success": False, "message": f"Error updating reward points: {str(update_error)}"})
435
 
436
  # Clear the cart after placing the order
437
  for item in cart_items: