nagasurendra commited on
Commit
5233fbf
·
verified ·
1 Parent(s): d17cd9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -33
app.py CHANGED
@@ -190,54 +190,81 @@ def reward_status():
190
  next_tier=next_tier,
191
  tiers=tiers
192
  )
193
- @app.route("/order/items", methods=["GET"])
194
- def order_items():
195
- email = session.get('user_email') # Fetch logged-in user's email
 
 
196
  if not email:
197
- print("No user email found. Redirecting to login.")
198
- return redirect(url_for("login"))
199
 
 
200
  try:
201
- # Fetch the most recent order for the user
202
  print(f"Fetching order details for email: {email}")
203
- result = sf.query(f"""
204
- SELECT Id, Order_Details__c
 
 
205
  FROM Order__c
206
  WHERE Customer_Email__c = '{email}'
207
  ORDER BY CreatedDate DESC
208
  LIMIT 1
209
- """)
210
-
211
- # Check if the query was successful and print the result
212
- print("Query result:", result)
213
 
214
- order = result.get("records", [])[0] if result.get("records") else None
215
 
216
- if not order:
217
- print("No order found for the user.")
218
- return render_template("order_items.html", items=None)
 
219
 
220
- # Extract item names from the order details
221
- item_names = []
222
- if order.get("Order_Details__c"):
223
- print("Found order details. Extracting item names.")
224
- for line in order["Order_Details__c"].split('\n'):
225
- item_parts = line.split('|')
226
- if item_parts:
227
- item_name = item_parts[0].strip() # Assuming the item name is the first part
228
- item_names.append(item_name)
229
- print(f"Extracted item: {item_name}") # Print each extracted item name
230
 
231
- if item_names:
232
- print(f"Total items extracted: {len(item_names)}")
233
- else:
234
- print("No items found in order details.")
235
 
236
- return render_template("order_items.html", items=item_names)
237
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  except Exception as e:
239
- print(f"Error fetching order details: {str(e)}")
240
- return render_template("order_items.html", items=None, error=str(e))
 
241
 
242
  @app.route("/logout")
243
  def logout():
 
190
  next_tier=next_tier,
191
  tiers=tiers
192
  )
193
+ @app.route('/order_summary')
194
+ def order_summary():
195
+ # Get the user email from session (assuming the session is already set during checkout)
196
+ email = session.get('user_email')
197
+
198
  if not email:
199
+ print("User not logged in. Redirecting to login.")
200
+ return "User not logged in", 400
201
 
202
+ # Query Salesforce to fetch the most recent order details
203
  try:
 
204
  print(f"Fetching order details for email: {email}")
205
+
206
+ # Query the Order__c object based on the user's email
207
+ query = f"""
208
+ SELECT Id, Customer_Name__c, Customer_Email__c, Total_Amount__c, Order_Details__c, Order_Status__c, Discount__c, Total_Bill__c
209
  FROM Order__c
210
  WHERE Customer_Email__c = '{email}'
211
  ORDER BY CreatedDate DESC
212
  LIMIT 1
213
+ """
214
+ result = sf.query(query)
 
 
215
 
216
+ print("Salesforce query result:", result)
217
 
218
+ # Check if the order record was found
219
+ if not result.get("records"):
220
+ print("No order found for this user.")
221
+ return "No order found for this user", 400
222
 
223
+ # Get the most recent order details
224
+ order = result["records"][0]
225
+ print(f"Order found: {order}")
 
 
 
 
 
 
 
226
 
227
+ # Extract details from the order
228
+ order_details = order.get("Order_Details__c", "")
229
+ print(f"Order details fetched: {order_details}")
 
230
 
231
+ order_items = []
232
 
233
+ if order_details:
234
+ print("Processing order details...")
235
+ for line in order_details.split('\n'):
236
+ item_parts = line.split('|')
237
+ if len(item_parts) >= 5:
238
+ item_name = item_parts[0].strip()
239
+ item_addons = item_parts[1].strip().replace('Add-Ons:', '')
240
+ item_instructions = item_parts[2].strip().replace('Instructions:', '')
241
+ item_price = item_parts[3].strip().replace('Price:', '')
242
+ item_image_url = item_parts[4].strip().replace('Image:', '')
243
+ order_items.append({
244
+ "name": item_name,
245
+ "addons": item_addons,
246
+ "instructions": item_instructions,
247
+ "price": item_price,
248
+ "image_url": item_image_url
249
+ })
250
+ print(f"Extracted item: {item_name} with price {item_price}")
251
+
252
+ if not order_items:
253
+ print("No items found in order details.")
254
+ else:
255
+ print(f"Total items extracted: {len(order_items)}")
256
+
257
+ # Pass these values to your template
258
+ return render_template(
259
+ 'order_summary.html',
260
+ order=order,
261
+ order_items=order_items
262
+ )
263
+
264
  except Exception as e:
265
+ print(f"Error querying Salesforce: {str(e)}")
266
+ return f"Error querying Salesforce: {str(e)}", 500
267
+
268
 
269
  @app.route("/logout")
270
  def logout():