Rammohan0504 commited on
Commit
a03a848
·
verified ·
1 Parent(s): 6318652

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py CHANGED
@@ -1102,6 +1102,52 @@ def checkout():
1102
  print(f"Error during checkout: {str(e)}")
1103
  return jsonify({"success": False, "error": str(e)})
1104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1105
  @app.route("/order", methods=["GET"])
1106
  def order_summary():
1107
  email = session.get('user_email') # Fetch logged-in user's email
 
1102
  print(f"Error during checkout: {str(e)}")
1103
  return jsonify({"success": False, "error": str(e)})
1104
 
1105
+
1106
+
1107
+ @app.route('/cart/add', methods=['POST'])
1108
+ def add_to_cart():
1109
+ data = request.json
1110
+ item_name = data.get('itemName')
1111
+
1112
+ if not item_name:
1113
+ return jsonify({"success": False, "error": "Item name is required."}), 400
1114
+
1115
+ try:
1116
+ email = session.get('user_email')
1117
+ if not email:
1118
+ return jsonify({"success": False, "error": "User not logged in."}), 401
1119
+
1120
+ # Fetch the item details (price, image, etc.) from Salesforce or your database
1121
+ item_query = f"SELECT Name, Price__c, Image1__c FROM Menu_Item__c WHERE Name = '{item_name}'"
1122
+ result = sf.query(item_query)
1123
+
1124
+ if not result.get('records'):
1125
+ return jsonify({"success": False, "error": "Item not found."}), 404
1126
+
1127
+ item = result['records'][0]
1128
+ item_price = item.get('Price__c', 0)
1129
+ item_image = item.get('Image1__c', '/static/placeholder.jpg')
1130
+
1131
+ # Add the item to the user's cart
1132
+ cart_item = {
1133
+ 'Name': item_name,
1134
+ 'Price__c': item_price,
1135
+ 'Base_Price__c': item_price,
1136
+ 'Quantity__c': 1,
1137
+ 'Image1__c': item_image,
1138
+ 'Customer_Email__c': email,
1139
+ 'Instructions__c': '', # You can add logic to handle user instructions if needed
1140
+ }
1141
+
1142
+ # Insert the item into the cart
1143
+ sf.Cart_Item__c.create(cart_item)
1144
+
1145
+ return jsonify({"success": True, "message": "Item added to cart successfully."})
1146
+
1147
+ except Exception as e:
1148
+ return jsonify({"success": False, "error": str(e)}), 500
1149
+
1150
+
1151
  @app.route("/order", methods=["GET"])
1152
  def order_summary():
1153
  email = session.get('user_email') # Fetch logged-in user's email