Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1107,25 +1107,25 @@ def checkout():
|
|
1107 |
@app.route('/cart/add', methods=['POST'], endpoint='add_to_cart_v2')
|
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
|
1114 |
|
1115 |
try:
|
1116 |
email = session.get('user_email') # Ensure user is logged in
|
1117 |
if not email:
|
1118 |
return jsonify({"success": False, "error": "User not logged in."}), 401
|
1119 |
|
1120 |
-
# Fetch
|
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
|
|
|
1107 |
@app.route('/cart/add', methods=['POST'], endpoint='add_to_cart_v2')
|
1108 |
def add_to_cart():
|
1109 |
data = request.json
|
1110 |
+
item_name = data.get('itemName') # Item name to add to the cart
|
1111 |
+
item_price = data.get('itemPrice') # Item price to add to the cart
|
1112 |
|
1113 |
+
if not item_name or not item_price:
|
1114 |
+
return jsonify({"success": False, "error": "Item name and price are required."}), 400
|
1115 |
|
1116 |
try:
|
1117 |
email = session.get('user_email') # Ensure user is logged in
|
1118 |
if not email:
|
1119 |
return jsonify({"success": False, "error": "User not logged in."}), 401
|
1120 |
|
1121 |
+
# Fetch item details (price, image, etc.) from Salesforce or your database if needed
|
1122 |
item_query = f"SELECT Name, Price__c, Image1__c FROM Menu_Item__c WHERE Name = '{item_name}'"
|
1123 |
result = sf.query(item_query)
|
1124 |
+
|
1125 |
if not result.get('records'):
|
1126 |
return jsonify({"success": False, "error": "Item not found."}), 404
|
1127 |
|
1128 |
item = result['records'][0]
|
|
|
1129 |
item_image = item.get('Image1__c', '/static/placeholder.jpg')
|
1130 |
|
1131 |
# Add the item to the user's cart
|