nagasurendra commited on
Commit
1f35c01
·
verified ·
1 Parent(s): 62801cd

Update cart.py

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