nagasurendra commited on
Commit
6d168f2
·
verified ·
1 Parent(s): 4adb7bb

Update order.py

Browse files
Files changed (1) hide show
  1. order.py +27 -47
order.py CHANGED
@@ -29,71 +29,51 @@ def order_summary():
29
  except Exception as e:
30
  print(f"Error fetching order details: {str(e)}")
31
  return render_template("order.html", order=None, error=str(e))
32
- @order_blueprint.route("/order/details", methods=["GET"])
33
- def order_item_details():
34
  email = session.get('user_email') # Fetch logged-in user's email
35
  if not email:
 
36
  return redirect(url_for("login"))
37
 
38
  try:
39
  # Fetch the most recent order for the user
 
40
  result = sf.query(f"""
41
- SELECT Id, Customer_Name__c, Customer_Email__c, Total_Amount__c, Order_Details__c, Order_Status__c, Discount__c, Total_Bill__c
42
  FROM Order__c
43
  WHERE Customer_Email__c = '{email}'
44
  ORDER BY CreatedDate DESC
45
  LIMIT 1
46
  """)
 
 
 
 
47
  order = result.get("records", [])[0] if result.get("records") else None
48
 
49
  if not order:
50
- return render_template("order.html", order=None)
 
51
 
52
- # Process Order Details
53
- order_items = []
54
- for line in order.Order_Details__c.split('\n'):
55
- item_parts = line.split('|')
56
- item_name = item_parts[0].strip()
 
 
 
 
 
57
 
58
- # Fetch item details from Menu_Item__c based on item name
59
- menu_item = sf.query(f"""
60
- SELECT Item_Name__c, Image_URL__c, Ingredient_1__r.Ingredient_Name__c, Ingredient_2__r.Ingredient_Name__c,
61
- Ingredient_1__r.Ingredient_Image__c, Ingredient_2__r.Ingredient_Image__c,
62
- Ingredient_1__r.Health_Benefits__c, Ingredient_2__r.Health_Benefits__c,
63
- Ingredient_1__r.Fun_Facts__c, Ingredient_2__r.Fun_Facts__c
64
- FROM Menu_Item__c
65
- WHERE Item_Name__c = '{item_name}'
66
- LIMIT 1
67
- """)
68
 
69
- if menu_item.get("records"):
70
- item_details = menu_item["records"][0]
71
- ingredients = {
72
- "ingredient_1": {
73
- "name": item_details.get("Ingredient_1__r").get("Ingredient_Name__c"),
74
- "image": item_details.get("Ingredient_1__r").get("Ingredient_Image__c"),
75
- "health_benefits": item_details.get("Ingredient_1__r").get("Health_Benefits__c"),
76
- "fun_facts": item_details.get("Ingredient_1__r").get("Fun_Facts__c")
77
- },
78
- "ingredient_2": {
79
- "name": item_details.get("Ingredient_2__r").get("Ingredient_Name__c"),
80
- "image": item_details.get("Ingredient_2__r").get("Ingredient_Image__c"),
81
- "health_benefits": item_details.get("Ingredient_2__r").get("Health_Benefits__c"),
82
- "fun_facts": item_details.get("Ingredient_2__r").get("Fun_Facts__c")
83
- }
84
- }
85
-
86
- # Prepare the item details and append to order_items list
87
- order_items.append({
88
- "item_name": item_name,
89
- "price": item_parts[3].strip().replace('Price:', ''),
90
- "image_url": item_parts[4].strip().replace('Image:', ''),
91
- "ingredients": ingredients
92
- })
93
-
94
- return render_template("reward_status.html", order_items=order_items, order=order)
95
 
96
  except Exception as e:
97
  print(f"Error fetching order details: {str(e)}")
98
- return render_template("order_details.html", order=None, error=str(e))
99
-
 
29
  except Exception as e:
30
  print(f"Error fetching order details: {str(e)}")
31
  return render_template("order.html", order=None, error=str(e))
32
+ @order_blueprint.route("/order/items", methods=["GET"])
33
+ def order_items():
34
  email = session.get('user_email') # Fetch logged-in user's email
35
  if not email:
36
+ print("No user email found. Redirecting to login.")
37
  return redirect(url_for("login"))
38
 
39
  try:
40
  # Fetch the most recent order for the user
41
+ print(f"Fetching order details for email: {email}")
42
  result = sf.query(f"""
43
+ SELECT Id, Order_Details__c
44
  FROM Order__c
45
  WHERE Customer_Email__c = '{email}'
46
  ORDER BY CreatedDate DESC
47
  LIMIT 1
48
  """)
49
+
50
+ # Check if the query was successful and print the result
51
+ print("Query result:", result)
52
+
53
  order = result.get("records", [])[0] if result.get("records") else None
54
 
55
  if not order:
56
+ print("No order found for the user.")
57
+ return render_template("order_items.html", items=None)
58
 
59
+ # Extract item names from the order details
60
+ item_names = []
61
+ if order.get("Order_Details__c"):
62
+ print("Found order details. Extracting item names.")
63
+ for line in order["Order_Details__c"].split('\n'):
64
+ item_parts = line.split('|')
65
+ if item_parts:
66
+ item_name = item_parts[0].strip() # Assuming the item name is the first part
67
+ item_names.append(item_name)
68
+ print(f"Extracted item: {item_name}") # Print each extracted item name
69
 
70
+ if item_names:
71
+ print(f"Total items extracted: {len(item_names)}")
72
+ else:
73
+ print("No items found in order details.")
 
 
 
 
 
 
74
 
75
+ return render_template("order_items.html", items=item_names)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
  except Exception as e:
78
  print(f"Error fetching order details: {str(e)}")
79
+ return render_template("order_items.html", items=None, error=str(e))