nagasurendra commited on
Commit
9d3e1c8
·
verified ·
1 Parent(s): c3589d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -38
app.py CHANGED
@@ -349,50 +349,30 @@ def update_quantity():
349
  return jsonify({"success": False, "error": str(e)}), 500
350
 
351
 
352
- @app.route("/checkout", methods=["POST"])
353
- def checkout():
354
- email = session.get('user_email')
355
- user_id = session.get('user_id')
356
- if not email or not user_id:
357
- return jsonify({"success": False, "message": "User not logged in"})
358
 
359
  try:
360
- # Fetch cart items for the user
361
  result = sf.query(f"""
362
- SELECT Id, Name, Price__c, Add_Ons_Price__c, Quantity__c, Add_Ons__c
363
- FROM Cart_Item__c
364
  WHERE Customer_Email__c = '{email}'
 
 
365
  """)
366
- cart_items = result.get("records", [])
367
- if not cart_items:
368
- return jsonify({"success": False, "message": "Cart is empty"})
369
-
370
- # Calculate the total price of the order
371
- total_price = sum(item['Price__c'] for item in cart_items)
372
-
373
- # Create the order in Salesforce
374
- order_data = {
375
- "Customer_Name__c": user_id,
376
- "Customer_Email__c": email,
377
- "Total_Amount__c": total_price,
378
- "Order_Status__c": "Pending",
379
- "Order_Items__c": "\n".join(
380
- [f"{item['Name']} (Qty: {item['Quantity__c']})" for item in cart_items]
381
- ),
382
- "Add_Ons__c": "\n".join(
383
- [item['Add_Ons__c'] if item.get('Add_Ons__c') else "None" for item in cart_items]
384
- ),
385
- }
386
- sf.Order__c.create(order_data)
387
-
388
- # Clear the cart after placing the order
389
- for item in cart_items:
390
- sf.Cart_Item__c.delete(item["Id"])
391
-
392
- return jsonify({"success": True, "message": "Order placed successfully!"})
393
  except Exception as e:
394
- print(f"Error during checkout: {str(e)}")
395
- return jsonify({"success": False, "error": str(e)})
396
 
397
 
398
  if __name__ == "__main__":
 
349
  return jsonify({"success": False, "error": str(e)}), 500
350
 
351
 
352
+ @app.route("/order", methods=["GET"])
353
+ def order_summary():
354
+ email = session.get('user_email') # Fetch logged-in user's email
355
+ if not email:
356
+ return redirect(url_for("login"))
 
357
 
358
  try:
359
+ # Fetch the most recent order for the logged-in user
360
  result = sf.query(f"""
361
+ SELECT Id, Customer_Name__c, Customer_Email__c, Total_Amount__c, Order_Items__c, Add_Ons__c, Order_Status__c
362
+ FROM Order__c
363
  WHERE Customer_Email__c = '{email}'
364
+ ORDER BY CreatedDate DESC
365
+ LIMIT 1
366
  """)
367
+ order = result.get("records", [])[0] if result.get("records") else None
368
+
369
+ if not order:
370
+ return render_template("order.html", order=None)
371
+
372
+ return render_template("order.html", order=order)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
373
  except Exception as e:
374
+ print(f"Error fetching order details: {str(e)}")
375
+ return render_template("order.html", order=None, error=str(e))
376
 
377
 
378
  if __name__ == "__main__":