Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1040,13 +1040,11 @@ def checkout():
|
|
| 1040 |
has_coupons = bool(coupon_query["records"])
|
| 1041 |
print(f"Has Coupons: {has_coupons}") # Debugging coupon presence check
|
| 1042 |
|
| 1043 |
-
|
| 1044 |
-
|
| 1045 |
-
# Valid coupon: Apply discount
|
| 1046 |
discount = total_price * 0.10 # Example: 10% discount
|
| 1047 |
print(f"Discount Applied: {discount}") # Debugging discount calculation
|
| 1048 |
-
|
| 1049 |
-
# Ensure the coupon is valid and exists
|
| 1050 |
referral_coupon_id = coupon_query["records"][0]["Id"]
|
| 1051 |
print(f"Referral Coupon ID: {referral_coupon_id}") # Debugging referral coupon ID
|
| 1052 |
|
|
@@ -1064,13 +1062,13 @@ def checkout():
|
|
| 1064 |
updated_coupons_str = None # Set to None if no coupons are left
|
| 1065 |
print("No Coupons Remaining. Setting to None") # Debugging no coupons left
|
| 1066 |
|
| 1067 |
-
# Update the Referral_Coupon__c record
|
| 1068 |
print(f"Updating Referral Coupon: {updated_coupons_str}") # Debugging update to Salesforce
|
| 1069 |
sf.Referral_Coupon__c.update(referral_coupon_id, {
|
| 1070 |
"Coupon_Code__c": updated_coupons_str
|
| 1071 |
})
|
| 1072 |
else:
|
| 1073 |
-
# If no
|
| 1074 |
reward_points_to_add = total_price * 0.10 # Example: 10% reward points
|
| 1075 |
print(f"Reward Points to Add: {reward_points_to_add}") # Debugging reward points
|
| 1076 |
|
|
@@ -1080,7 +1078,7 @@ def checkout():
|
|
| 1080 |
WHERE Email__c = '{email}'
|
| 1081 |
""")
|
| 1082 |
print(f"Customer Reward Points Query: {customer_record}") # Debugging customer reward points query
|
| 1083 |
-
|
| 1084 |
customer = customer_record.get("records", [])[0] if customer_record else None
|
| 1085 |
if customer:
|
| 1086 |
current_reward_points = customer.get("Reward_Points__c") or 0
|
|
@@ -1093,7 +1091,6 @@ def checkout():
|
|
| 1093 |
"Reward_Points__c": new_reward_points
|
| 1094 |
})
|
| 1095 |
|
| 1096 |
-
|
| 1097 |
# Final total bill calculation
|
| 1098 |
total_bill = total_price - discount
|
| 1099 |
print(f"Total Bill After Discount: {total_bill}") # Debugging final total bill
|
|
|
|
| 1040 |
has_coupons = bool(coupon_query["records"])
|
| 1041 |
print(f"Has Coupons: {has_coupons}") # Debugging coupon presence check
|
| 1042 |
|
| 1043 |
+
if selected_coupon:
|
| 1044 |
+
# Apply 10% discount if a valid coupon is selected
|
|
|
|
| 1045 |
discount = total_price * 0.10 # Example: 10% discount
|
| 1046 |
print(f"Discount Applied: {discount}") # Debugging discount calculation
|
| 1047 |
+
|
|
|
|
| 1048 |
referral_coupon_id = coupon_query["records"][0]["Id"]
|
| 1049 |
print(f"Referral Coupon ID: {referral_coupon_id}") # Debugging referral coupon ID
|
| 1050 |
|
|
|
|
| 1062 |
updated_coupons_str = None # Set to None if no coupons are left
|
| 1063 |
print("No Coupons Remaining. Setting to None") # Debugging no coupons left
|
| 1064 |
|
| 1065 |
+
# Update the Referral_Coupon__c record
|
| 1066 |
print(f"Updating Referral Coupon: {updated_coupons_str}") # Debugging update to Salesforce
|
| 1067 |
sf.Referral_Coupon__c.update(referral_coupon_id, {
|
| 1068 |
"Coupon_Code__c": updated_coupons_str
|
| 1069 |
})
|
| 1070 |
else:
|
| 1071 |
+
# If no coupon is selected, add reward points
|
| 1072 |
reward_points_to_add = total_price * 0.10 # Example: 10% reward points
|
| 1073 |
print(f"Reward Points to Add: {reward_points_to_add}") # Debugging reward points
|
| 1074 |
|
|
|
|
| 1078 |
WHERE Email__c = '{email}'
|
| 1079 |
""")
|
| 1080 |
print(f"Customer Reward Points Query: {customer_record}") # Debugging customer reward points query
|
| 1081 |
+
|
| 1082 |
customer = customer_record.get("records", [])[0] if customer_record else None
|
| 1083 |
if customer:
|
| 1084 |
current_reward_points = customer.get("Reward_Points__c") or 0
|
|
|
|
| 1091 |
"Reward_Points__c": new_reward_points
|
| 1092 |
})
|
| 1093 |
|
|
|
|
| 1094 |
# Final total bill calculation
|
| 1095 |
total_bill = total_price - discount
|
| 1096 |
print(f"Total Bill After Discount: {total_bill}") # Debugging final total bill
|