Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -349,50 +349,30 @@ def update_quantity():
|
|
349 |
return jsonify({"success": False, "error": str(e)}), 500
|
350 |
|
351 |
|
352 |
-
@app.route("/
|
353 |
-
def
|
354 |
-
email = session.get('user_email')
|
355 |
-
|
356 |
-
|
357 |
-
return jsonify({"success": False, "message": "User not logged in"})
|
358 |
|
359 |
try:
|
360 |
-
# Fetch
|
361 |
result = sf.query(f"""
|
362 |
-
SELECT Id,
|
363 |
-
FROM
|
364 |
WHERE Customer_Email__c = '{email}'
|
|
|
|
|
365 |
""")
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
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
|
395 |
-
return
|
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__":
|