nagasurendra commited on
Commit
e4a58d1
·
verified ·
1 Parent(s): 27c8731

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -54
app.py CHANGED
@@ -344,62 +344,57 @@ def cart():
344
  else:
345
  coupons = []
346
 
347
- # Inside your /cart route:
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
- # Determine the category filter (Veg/Non veg/All)
355
- if category == 'Veg':
356
- category_filter = "Veg"
357
- elif category == 'Non veg':
358
- category_filter = "Non veg"
359
- else: # If category is 'All'
360
- category_filter = "All"
361
-
362
- # Define section-to-complementary section mapping
363
- complementary_sections = {
364
- 'Breads': ['Curries', 'Biryanis', 'Starters'],
365
- 'Biryanis': ['Curries', 'Starters', 'Desserts'],
366
- 'Curries': ['Rice', 'Breads', 'Starters'],
367
- 'Starters': ['Biryanis', 'Curries', 'Desserts'],
368
- 'Desserts': ['Biryanis', 'Curries', 'Soft Drinks'],
369
- 'Soft Drinks': ['Starters', 'Biryanis', 'Curries']
370
- }
371
-
372
- # Get the complementary sections for the selected section
373
- suggested_sections = complementary_sections.get(section, [])
374
-
375
- # Fetch suggestions from the complementary sections
376
- try:
377
- # Loop through complementary sections and fetch the relevant items
378
- for suggested_section in suggested_sections:
379
- # If category is "All", we can fetch both Veg and Non veg items from the complementary section
380
- if category_filter == "All":
381
- query = f"""
382
- SELECT Name, Price__c, Image1__c
383
- FROM Menu_Item__c
384
- WHERE Section__c = '{suggested_section}'
385
- AND (Veg_NonVeg__c = 'Veg' OR Veg_NonVeg__c = 'Non veg')
386
- LIMIT 4
387
- """
388
- else:
389
- # Otherwise, fetch only Veg or Non veg items depending on the selected category
390
- query = f"""
391
- SELECT Name, Price__c, Image1__c
392
- FROM Menu_Item__c
393
- WHERE Section__c = '{suggested_section}'
394
- AND Veg_NonVeg__c = '{category_filter}'
395
- LIMIT 4
396
- """
397
- suggestion_result = sf.query(query)
398
- suggestions.extend(suggestion_result.get("records", [])) # Add all suggestions from each section
399
-
400
- except Exception as e:
401
- print(f"Error fetching suggestions: {e}")
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",