Update cart.py
Browse files
cart.py
CHANGED
|
@@ -418,5 +418,39 @@ def checkout():
|
|
| 418 |
except Exception as e:
|
| 419 |
print(f"Error during checkout: {str(e)}") # Debugging error message
|
| 420 |
return jsonify({"success": False, "error": str(e)})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 421 |
|
| 422 |
|
|
|
|
| 418 |
except Exception as e:
|
| 419 |
print(f"Error during checkout: {str(e)}") # Debugging error message
|
| 420 |
return jsonify({"success": False, "error": str(e)})
|
| 421 |
+
@cart_blueprint.route("/fetch_previous_order", methods=["GET"])
|
| 422 |
+
def fetch_previous_order():
|
| 423 |
+
# Assuming `email` is the unique identifier for the user
|
| 424 |
+
email = session.get('user_email')
|
| 425 |
+
|
| 426 |
+
if not email:
|
| 427 |
+
return jsonify({"success": False, "message": "User not logged in"})
|
| 428 |
+
|
| 429 |
+
try:
|
| 430 |
+
# Fetch the most recent order (or any other logic to get the previous order)
|
| 431 |
+
previous_order_query = f"""
|
| 432 |
+
SELECT Order_Details__c
|
| 433 |
+
FROM Order__c
|
| 434 |
+
WHERE Customer_Email__c = '{email}' AND Order_Status__c = 'Completed'
|
| 435 |
+
ORDER BY CreatedDate DESC LIMIT 1
|
| 436 |
+
"""
|
| 437 |
+
previous_order_result = sf.query(previous_order_query)
|
| 438 |
+
previous_order = previous_order_result["records"][0] if previous_order_result["records"] else None
|
| 439 |
+
|
| 440 |
+
if not previous_order:
|
| 441 |
+
return jsonify({"success": False, "message": "No previous order found."})
|
| 442 |
+
|
| 443 |
+
# Parse the order details to extract the items and add-ons
|
| 444 |
+
order_details = previous_order["Order_Details__c"]
|
| 445 |
+
|
| 446 |
+
# Assuming the order details are stored as JSON (you can use JSON.parse() in JavaScript to handle this)
|
| 447 |
+
# You might need to adjust the parsing based on how the data is structured (whether it's JSON or string-based)
|
| 448 |
+
order_items = json.loads(order_details)["items"]
|
| 449 |
+
|
| 450 |
+
return jsonify({"success": True, "previousOrder": order_items})
|
| 451 |
+
|
| 452 |
+
except Exception as e:
|
| 453 |
+
print(f"Error fetching previous order: {e}")
|
| 454 |
+
return jsonify({"success": False, "message": "Error fetching previous order."})
|
| 455 |
|
| 456 |
|