geethareddy commited on
Commit
8a57edf
·
verified ·
1 Parent(s): 0ce11c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -615,14 +615,15 @@ def menu():
615
  )
616
 
617
 
618
- def cart_page():
 
619
  email = session.get('user_email')
620
  if not email:
621
  return redirect(url_for("login"))
622
 
623
  try:
624
  # Fetch cart items with Category and Section
625
- result = salesforce.sf.query(f"""
626
  SELECT Name, Price__c, Quantity__c, Add_Ons__c, Add_Ons_Price__c, Image1__c, Instructions__c, Category__c, Section__c
627
  FROM Cart_Item__c
628
  WHERE Customer_Email__c = '{email}'
@@ -632,7 +633,7 @@ def cart_page():
632
  subtotal = sum(item['Price__c'] for item in cart_items)
633
 
634
  # Fetch reward points
635
- customer_result = salesforce.sf.query(f"""
636
  SELECT Reward_Points__c
637
  FROM Customer_Login__c
638
  WHERE Email__c = '{email}'
@@ -640,19 +641,21 @@ def cart_page():
640
  reward_points = customer_result['records'][0].get('Reward_Points__c', 0) if customer_result['records'] else 0
641
 
642
  # Fetch coupons for the user
643
- coupon_result = salesforce.sf.query(f"""
644
  SELECT Coupon_Code__c FROM Referral_Coupon__c WHERE Referral_Email__c = '{email}'
645
  """)
646
- coupons = []
647
  if coupon_result["records"]:
648
  raw_coupons = coupon_result["records"][0].get("Coupon_Code__c", "")
649
  coupons = raw_coupons.split("\n") if raw_coupons else []
 
 
650
 
651
  # Initialize suggestions as an empty list
652
  suggestions = []
653
 
654
  # If there are items in the cart, fetch suggestions
655
  if cart_items:
 
656
  first_item = cart_items[0]
657
  item_category = first_item.get('Category__c', 'All') # Default to 'All' if not found
658
  item_section = first_item.get('Section__c', 'Biryanis') # Default to 'Biryanis' if not found
@@ -667,8 +670,10 @@ def cart_page():
667
  'Soft Drinks': ['Starters', 'Biryanis', 'Curries']
668
  }
669
 
 
670
  suggested_sections = complementary_sections.get(item_section, [])
671
 
 
672
  try:
673
  for suggested_section in suggested_sections:
674
  if item_category == "All":
@@ -687,9 +692,10 @@ def cart_page():
687
  AND Veg_NonVeg__c = '{item_category}'
688
  LIMIT 4
689
  """
690
- suggestion_result = salesforce.sf.query(query)
691
- suggestions.extend(suggestion_result.get("records", []))
692
 
 
693
  if len(suggestions) > 4:
694
  suggestions = suggestions[:4]
695
 
 
615
  )
616
 
617
 
618
+ @app.route("/cart", methods=["GET"])
619
+ def cart():
620
  email = session.get('user_email')
621
  if not email:
622
  return redirect(url_for("login"))
623
 
624
  try:
625
  # Fetch cart items with Category and Section
626
+ result = sf.query(f"""
627
  SELECT Name, Price__c, Quantity__c, Add_Ons__c, Add_Ons_Price__c, Image1__c, Instructions__c, Category__c, Section__c
628
  FROM Cart_Item__c
629
  WHERE Customer_Email__c = '{email}'
 
633
  subtotal = sum(item['Price__c'] for item in cart_items)
634
 
635
  # Fetch reward points
636
+ customer_result = sf.query(f"""
637
  SELECT Reward_Points__c
638
  FROM Customer_Login__c
639
  WHERE Email__c = '{email}'
 
641
  reward_points = customer_result['records'][0].get('Reward_Points__c', 0) if customer_result['records'] else 0
642
 
643
  # Fetch coupons for the user
644
+ coupon_result = sf.query(f"""
645
  SELECT Coupon_Code__c FROM Referral_Coupon__c WHERE Referral_Email__c = '{email}'
646
  """)
 
647
  if coupon_result["records"]:
648
  raw_coupons = coupon_result["records"][0].get("Coupon_Code__c", "")
649
  coupons = raw_coupons.split("\n") if raw_coupons else []
650
+ else:
651
+ coupons = []
652
 
653
  # Initialize suggestions as an empty list
654
  suggestions = []
655
 
656
  # If there are items in the cart, fetch suggestions
657
  if cart_items:
658
+ # Get the category and section of the first item in the cart (You can choose which item you want to base suggestions on)
659
  first_item = cart_items[0]
660
  item_category = first_item.get('Category__c', 'All') # Default to 'All' if not found
661
  item_section = first_item.get('Section__c', 'Biryanis') # Default to 'Biryanis' if not found
 
670
  'Soft Drinks': ['Starters', 'Biryanis', 'Curries']
671
  }
672
 
673
+ # Get the complementary sections for the selected section
674
  suggested_sections = complementary_sections.get(item_section, [])
675
 
676
+ # Fetch suggestions from the complementary sections
677
  try:
678
  for suggested_section in suggested_sections:
679
  if item_category == "All":
 
692
  AND Veg_NonVeg__c = '{item_category}'
693
  LIMIT 4
694
  """
695
+ suggestion_result = sf.query(query)
696
+ suggestions.extend(suggestion_result.get("records", [])) # Add suggestions from each section
697
 
698
+ # Limit the number of suggestions to 4
699
  if len(suggestions) > 4:
700
  suggestions = suggestions[:4]
701