Update cart.py
Browse files
cart.py
CHANGED
@@ -375,10 +375,9 @@ def checkout():
|
|
375 |
def get_loyalty_data():
|
376 |
email = session.get('user_email')
|
377 |
if not email:
|
378 |
-
return redirect(url_for('login'))
|
379 |
|
380 |
try:
|
381 |
-
# Fetch customer loyalty data
|
382 |
customer_record = sf.query(f"""
|
383 |
SELECT Reward_Points__c, Total_Orders__c, Total_Spent__c, Badge__c
|
384 |
FROM Customer_Login__c WHERE Email__c = '{email}'
|
@@ -387,18 +386,33 @@ def get_loyalty_data():
|
|
387 |
if not customer:
|
388 |
return "Customer not found", 404
|
389 |
|
390 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
391 |
rewards = [
|
392 |
-
{"name": "$5 Off", "points": 50, "description": "Get $5 off your next order"},
|
393 |
-
{"name": "Free Drink", "points": 100, "description": "Redeem for a free drink"},
|
394 |
-
{"name": "20% Off", "points": 200, "description": "20% off your next order"}
|
395 |
]
|
396 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
397 |
loyalty_data = {
|
398 |
-
"reward_points":
|
399 |
-
"total_orders":
|
400 |
-
"total_spent":
|
401 |
-
"badge":
|
|
|
402 |
"available_rewards": rewards
|
403 |
}
|
404 |
return render_template("loyalty.html", loyalty_data=loyalty_data)
|
|
|
375 |
def get_loyalty_data():
|
376 |
email = session.get('user_email')
|
377 |
if not email:
|
378 |
+
return redirect(url_for('login'))
|
379 |
|
380 |
try:
|
|
|
381 |
customer_record = sf.query(f"""
|
382 |
SELECT Reward_Points__c, Total_Orders__c, Total_Spent__c, Badge__c
|
383 |
FROM Customer_Login__c WHERE Email__c = '{email}'
|
|
|
386 |
if not customer:
|
387 |
return "Customer not found", 404
|
388 |
|
389 |
+
# Clean up data
|
390 |
+
reward_points = round(customer.get("Reward_Points__c", 0) or 0, 2) # Round to 2 decimals
|
391 |
+
total_orders = customer.get("Total_Orders__c", 0) or 0
|
392 |
+
total_spent = customer.get("Total_Spent__c", 0) or 0
|
393 |
+
badge = customer.get("Badge__c") or "Newbie" # Default to "Newbie" if None
|
394 |
+
|
395 |
+
# Define rewards with image URLs (you can store these in Salesforce or locally)
|
396 |
rewards = [
|
397 |
+
{"name": "$5 Off", "points": 50, "description": "Get $5 off your next order", "image": "/static/images/reward_discount.png"},
|
398 |
+
{"name": "Free Drink", "points": 100, "description": "Redeem for a free drink", "image": "/static/images/reward_drink.png"},
|
399 |
+
{"name": "20% Off", "points": 200, "description": "20% off your next order", "image": "/static/images/reward_percentage.png"}
|
400 |
]
|
401 |
|
402 |
+
# Badge images (map badge names to image paths)
|
403 |
+
badge_images = {
|
404 |
+
"Newbie": "/static/images/badge_bronze.png",
|
405 |
+
"Regular": "/static/images/badge_silver.png",
|
406 |
+
"VIP": "/static/images/badge_gold.png",
|
407 |
+
"Gold Member": "/static/images/badge_platinum.png"
|
408 |
+
}
|
409 |
+
|
410 |
loyalty_data = {
|
411 |
+
"reward_points": reward_points,
|
412 |
+
"total_orders": total_orders,
|
413 |
+
"total_spent": total_spent,
|
414 |
+
"badge": badge,
|
415 |
+
"badge_image": badge_images.get(badge, "/static/images/badge_bronze.png"), # Default to bronze
|
416 |
"available_rewards": rewards
|
417 |
}
|
418 |
return render_template("loyalty.html", loyalty_data=loyalty_data)
|