Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -309,23 +309,21 @@ def menu():
|
|
| 309 |
referral_code=referral_code,
|
| 310 |
reward_points=reward_points
|
| 311 |
)
|
| 312 |
-
|
| 313 |
@app.route("/cart", methods=["GET"])
|
| 314 |
def cart():
|
| 315 |
-
email = session.get('user_email')
|
| 316 |
if not email:
|
| 317 |
return redirect(url_for("login"))
|
| 318 |
|
| 319 |
try:
|
| 320 |
-
#
|
| 321 |
result = sf.query(f"""
|
| 322 |
-
SELECT Name, Price__c, Quantity__c, Add_Ons__c, Add_Ons_Price__c, Image1__c, Instructions__c
|
| 323 |
FROM Cart_Item__c
|
| 324 |
WHERE Customer_Email__c = '{email}'
|
| 325 |
""")
|
| 326 |
cart_items = result.get("records", [])
|
| 327 |
|
| 328 |
-
# Subtotal should be the sum of all item prices in the cart
|
| 329 |
subtotal = sum(item['Price__c'] for item in cart_items)
|
| 330 |
|
| 331 |
# Fetch reward points
|
|
@@ -340,26 +338,44 @@ def cart():
|
|
| 340 |
coupon_result = sf.query(f"""
|
| 341 |
SELECT Coupon_Code__c FROM Referral_Coupon__c WHERE Referral_Email__c = '{email}'
|
| 342 |
""")
|
| 343 |
-
|
| 344 |
-
# Extract and split coupons into a list
|
| 345 |
if coupon_result["records"]:
|
| 346 |
raw_coupons = coupon_result["records"][0].get("Coupon_Code__c", "")
|
| 347 |
coupons = raw_coupons.split("\n") if raw_coupons else []
|
| 348 |
else:
|
| 349 |
coupons = []
|
| 350 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
return render_template(
|
| 352 |
"cart.html",
|
| 353 |
cart_items=cart_items,
|
| 354 |
subtotal=subtotal,
|
| 355 |
reward_points=reward_points,
|
| 356 |
customer_email=email,
|
| 357 |
-
coupons=coupons
|
|
|
|
| 358 |
)
|
| 359 |
|
| 360 |
except Exception as e:
|
| 361 |
print(f"Error fetching cart items: {e}")
|
| 362 |
-
return render_template("cart.html", cart_items=[], subtotal=0, reward_points=0, coupons=[])
|
| 363 |
|
| 364 |
|
| 365 |
|
|
|
|
| 309 |
referral_code=referral_code,
|
| 310 |
reward_points=reward_points
|
| 311 |
)
|
|
|
|
| 312 |
@app.route("/cart", methods=["GET"])
|
| 313 |
def cart():
|
| 314 |
+
email = session.get('user_email')
|
| 315 |
if not email:
|
| 316 |
return redirect(url_for("login"))
|
| 317 |
|
| 318 |
try:
|
| 319 |
+
# Fetch cart items with Category and Section
|
| 320 |
result = sf.query(f"""
|
| 321 |
+
SELECT Name, Price__c, Quantity__c, Add_Ons__c, Add_Ons_Price__c, Image1__c, Instructions__c, Category__c, Section__c
|
| 322 |
FROM Cart_Item__c
|
| 323 |
WHERE Customer_Email__c = '{email}'
|
| 324 |
""")
|
| 325 |
cart_items = result.get("records", [])
|
| 326 |
|
|
|
|
| 327 |
subtotal = sum(item['Price__c'] for item in cart_items)
|
| 328 |
|
| 329 |
# Fetch reward points
|
|
|
|
| 338 |
coupon_result = sf.query(f"""
|
| 339 |
SELECT Coupon_Code__c FROM Referral_Coupon__c WHERE Referral_Email__c = '{email}'
|
| 340 |
""")
|
|
|
|
|
|
|
| 341 |
if coupon_result["records"]:
|
| 342 |
raw_coupons = coupon_result["records"][0].get("Coupon_Code__c", "")
|
| 343 |
coupons = raw_coupons.split("\n") if raw_coupons else []
|
| 344 |
else:
|
| 345 |
coupons = []
|
| 346 |
|
| 347 |
+
# Suggestion Logic
|
| 348 |
+
veg_breads_present = any(
|
| 349 |
+
item.get('Category__c') == 'Veg' and item.get('Section__c') == 'Breads'
|
| 350 |
+
for item in cart_items
|
| 351 |
+
)
|
| 352 |
+
|
| 353 |
+
suggestions = []
|
| 354 |
+
if veg_breads_present:
|
| 355 |
+
try:
|
| 356 |
+
suggestion_result = sf.query(f"""
|
| 357 |
+
SELECT Name, Price__c, Image1__c
|
| 358 |
+
FROM Menu_Item__c
|
| 359 |
+
WHERE Veg_NonVeg__c = 'Veg' AND Section__c = 'Curries'
|
| 360 |
+
LIMIT 10
|
| 361 |
+
""")
|
| 362 |
+
suggestions = suggestion_result.get("records", [])[:2]
|
| 363 |
+
except Exception as e:
|
| 364 |
+
print(f"Error fetching suggestions: {e}")
|
| 365 |
+
|
| 366 |
return render_template(
|
| 367 |
"cart.html",
|
| 368 |
cart_items=cart_items,
|
| 369 |
subtotal=subtotal,
|
| 370 |
reward_points=reward_points,
|
| 371 |
customer_email=email,
|
| 372 |
+
coupons=coupons,
|
| 373 |
+
suggestions=suggestions
|
| 374 |
)
|
| 375 |
|
| 376 |
except Exception as e:
|
| 377 |
print(f"Error fetching cart items: {e}")
|
| 378 |
+
return render_template("cart.html", cart_items=[], subtotal=0, reward_points=0, coupons=[], suggestions=[])
|
| 379 |
|
| 380 |
|
| 381 |
|