Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -481,6 +481,7 @@ def checkout():
|
|
481 |
WHERE Customer_Email__c = '{email}'
|
482 |
""")
|
483 |
cart_items = result.get("records", [])
|
|
|
484 |
if not cart_items:
|
485 |
return jsonify({"success": False, "message": "Cart is empty"})
|
486 |
|
@@ -548,16 +549,21 @@ def checkout():
|
|
548 |
|
549 |
sf.Order__c.create(order_data)
|
550 |
|
551 |
-
#
|
552 |
-
|
553 |
-
|
|
|
|
|
|
|
|
|
554 |
|
555 |
return jsonify({"success": True, "message": "Order placed successfully!"})
|
556 |
|
557 |
except Exception as e:
|
558 |
-
print(f"Error
|
559 |
return jsonify({"success": False, "error": str(e)})
|
560 |
|
|
|
561 |
@app.route("/order", methods=["GET"])
|
562 |
def order_summary():
|
563 |
email = session.get('user_email') # Fetch logged-in user's email
|
|
|
481 |
WHERE Customer_Email__c = '{email}'
|
482 |
""")
|
483 |
cart_items = result.get("records", [])
|
484 |
+
|
485 |
if not cart_items:
|
486 |
return jsonify({"success": False, "message": "Cart is empty"})
|
487 |
|
|
|
549 |
|
550 |
sf.Order__c.create(order_data)
|
551 |
|
552 |
+
# ✅ Fix: Check if cart items exist before deleting
|
553 |
+
if cart_items:
|
554 |
+
for item in cart_items:
|
555 |
+
try:
|
556 |
+
sf.Cart_Item__c.delete(item["Id"])
|
557 |
+
except Exception as e:
|
558 |
+
print(f"Error deleting cart item {item['Id']}: {str(e)}")
|
559 |
|
560 |
return jsonify({"success": True, "message": "Order placed successfully!"})
|
561 |
|
562 |
except Exception as e:
|
563 |
+
print(f"Error during checkout: {str(e)}")
|
564 |
return jsonify({"success": False, "error": str(e)})
|
565 |
|
566 |
+
|
567 |
@app.route("/order", methods=["GET"])
|
568 |
def order_summary():
|
569 |
email = session.get('user_email') # Fetch logged-in user's email
|