Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -344,62 +344,57 @@ def cart():
|
|
| 344 |
else:
|
| 345 |
coupons = []
|
| 346 |
|
| 347 |
-
#
|
| 348 |
-
|
| 349 |
-
category = request.args.get('category', 'All') # Get the category (default is 'All')
|
| 350 |
-
section = request.args.get('section', 'Biryanis') # Get the section (default is 'Biryanis')
|
| 351 |
-
|
| 352 |
suggestions = []
|
| 353 |
|
| 354 |
-
#
|
| 355 |
-
if
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
|
| 404 |
return render_template(
|
| 405 |
"cart.html",
|
|
|
|
| 344 |
else:
|
| 345 |
coupons = []
|
| 346 |
|
| 347 |
+
# Initialize suggestions as an empty list
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
suggestions = []
|
| 349 |
|
| 350 |
+
# If there are items in the cart, fetch suggestions
|
| 351 |
+
if cart_items:
|
| 352 |
+
# Get the category and section of the first item in the cart (You can choose which item you want to base suggestions on)
|
| 353 |
+
first_item = cart_items[0]
|
| 354 |
+
item_category = first_item.get('Category__c', 'All') # Default to 'All' if not found
|
| 355 |
+
item_section = first_item.get('Section__c', 'Biryanis') # Default to 'Biryanis' if not found
|
| 356 |
+
|
| 357 |
+
# Define section-to-complementary section mapping
|
| 358 |
+
complementary_sections = {
|
| 359 |
+
'Breads': ['Curries', 'Biryanis', 'Starters'],
|
| 360 |
+
'Biryanis': ['Curries', 'Starters', 'Desserts'],
|
| 361 |
+
'Curries': ['Rice', 'Breads', 'Starters'],
|
| 362 |
+
'Starters': ['Biryanis', 'Curries', 'Desserts'],
|
| 363 |
+
'Desserts': ['Biryanis', 'Curries', 'Soft Drinks'],
|
| 364 |
+
'Soft Drinks': ['Starters', 'Biryanis', 'Curries']
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
# Get the complementary sections for the selected section
|
| 368 |
+
suggested_sections = complementary_sections.get(item_section, [])
|
| 369 |
+
|
| 370 |
+
# Fetch suggestions from the complementary sections
|
| 371 |
+
try:
|
| 372 |
+
for suggested_section in suggested_sections:
|
| 373 |
+
if item_category == "All":
|
| 374 |
+
query = f"""
|
| 375 |
+
SELECT Name, Price__c, Image1__c
|
| 376 |
+
FROM Menu_Item__c
|
| 377 |
+
WHERE Section__c = '{suggested_section}'
|
| 378 |
+
AND (Veg_NonVeg__c = 'Veg' OR Veg_NonVeg__c = 'Non veg')
|
| 379 |
+
LIMIT 4
|
| 380 |
+
"""
|
| 381 |
+
else:
|
| 382 |
+
query = f"""
|
| 383 |
+
SELECT Name, Price__c, Image1__c
|
| 384 |
+
FROM Menu_Item__c
|
| 385 |
+
WHERE Section__c = '{suggested_section}'
|
| 386 |
+
AND Veg_NonVeg__c = '{item_category}'
|
| 387 |
+
LIMIT 4
|
| 388 |
+
"""
|
| 389 |
+
suggestion_result = sf.query(query)
|
| 390 |
+
suggestions.extend(suggestion_result.get("records", [])) # Add suggestions from each section
|
| 391 |
+
|
| 392 |
+
# Limit the number of suggestions to 4
|
| 393 |
+
if len(suggestions) > 4:
|
| 394 |
+
suggestions = suggestions[:4]
|
| 395 |
+
|
| 396 |
+
except Exception as e:
|
| 397 |
+
print(f"Error fetching suggestions: {e}")
|
|
|
|
| 398 |
|
| 399 |
return render_template(
|
| 400 |
"cart.html",
|