Update app.py
Browse files
app.py
CHANGED
@@ -241,6 +241,7 @@ def get_menu_items():
|
|
241 |
logger.error(f"Failed to fetch menu items: {str(e)}")
|
242 |
return jsonify({"error": f"Failed to fetch menu items from Salesforce: {str(e)}"}), 500
|
243 |
|
|
|
244 |
@app.route('/submit_customization_ingredients', methods=['POST'])
|
245 |
def submit_customization_ingredients():
|
246 |
global sf
|
@@ -271,21 +272,20 @@ def submit_customization_ingredients():
|
|
271 |
total_price = (base_price * quantity) + addons_price
|
272 |
|
273 |
# Check if item already exists in the cart for the user based on Customer_Email__c and Item Name
|
274 |
-
|
|
|
275 |
|
276 |
-
if existing_item: # If the item exists, update it
|
277 |
-
item_id = existing_item[0]['Id']
|
278 |
-
existing_quantity = existing_item[0]['Quantity__c']
|
279 |
-
existing_addons = existing_item[0]['Add_Ons__c']
|
280 |
-
existing_instructions = existing_item[0]['Instructions__c']
|
281 |
-
existing_price = existing_item[0]['Price__c']
|
282 |
|
283 |
# Update quantity, addons, and instructions
|
284 |
new_quantity = existing_quantity + quantity
|
285 |
-
# Ensure existing_addons and existing_instructions are never None or empty before concatenation
|
286 |
new_addons = (existing_addons or '') + (', ' + ingredient_names if ingredient_names else '')
|
287 |
new_instructions = (existing_instructions or '') + ('; ' + instructions if instructions else '')
|
288 |
-
|
289 |
|
290 |
# Calculate the new total price
|
291 |
updated_price = (base_price * new_quantity) + addons_price
|
@@ -323,21 +323,21 @@ def submit_customization_ingredients():
|
|
323 |
total_price = (base_price * quantity) + addons_price
|
324 |
|
325 |
# Check if the menu item already exists in the cart for the user
|
326 |
-
|
|
|
327 |
|
328 |
-
if existing_item: # If the item exists, update it
|
329 |
-
item_id = existing_item[0]['Id']
|
330 |
-
existing_quantity = existing_item[0]['Quantity__c']
|
331 |
-
existing_addons = existing_item[0]['Add_Ons__c']
|
332 |
-
existing_instructions = existing_item[0]['Instructions__c']
|
333 |
-
existing_price = existing_item[0]['Price__c']
|
334 |
|
335 |
# Update quantity, addons, and instructions
|
336 |
new_quantity = existing_quantity + quantity
|
337 |
-
# Ensure existing_addons and existing_instructions are never None or empty before concatenation
|
338 |
new_addons = (existing_addons or '') + (', ' + ingredient_names if ingredient_names else '')
|
339 |
new_instructions = (existing_instructions or '') + ('; ' + instructions if instructions else '')
|
340 |
-
|
341 |
# Calculate the new total price
|
342 |
updated_price = (base_price * new_quantity) + addons_price
|
343 |
|
|
|
241 |
logger.error(f"Failed to fetch menu items: {str(e)}")
|
242 |
return jsonify({"error": f"Failed to fetch menu items from Salesforce: {str(e)}"}), 500
|
243 |
|
244 |
+
|
245 |
@app.route('/submit_customization_ingredients', methods=['POST'])
|
246 |
def submit_customization_ingredients():
|
247 |
global sf
|
|
|
272 |
total_price = (base_price * quantity) + addons_price
|
273 |
|
274 |
# Check if item already exists in the cart for the user based on Customer_Email__c and Item Name
|
275 |
+
soql = f"SELECT Id, Quantity__c, Add_Ons__c, Instructions__c, Price__c FROM Cart_Item__c WHERE Customer_Email__c = '{customer_email}' AND Name = '{item['name']}' LIMIT 1"
|
276 |
+
existing_item = sf.query(soql)
|
277 |
|
278 |
+
if existing_item['records']: # If the item exists, update it
|
279 |
+
item_id = existing_item['records'][0]['Id']
|
280 |
+
existing_quantity = existing_item['records'][0]['Quantity__c']
|
281 |
+
existing_addons = existing_item['records'][0]['Add_Ons__c']
|
282 |
+
existing_instructions = existing_item['records'][0]['Instructions__c']
|
283 |
+
existing_price = existing_item['records'][0]['Price__c']
|
284 |
|
285 |
# Update quantity, addons, and instructions
|
286 |
new_quantity = existing_quantity + quantity
|
|
|
287 |
new_addons = (existing_addons or '') + (', ' + ingredient_names if ingredient_names else '')
|
288 |
new_instructions = (existing_instructions or '') + ('; ' + instructions if instructions else '')
|
|
|
289 |
|
290 |
# Calculate the new total price
|
291 |
updated_price = (base_price * new_quantity) + addons_price
|
|
|
323 |
total_price = (base_price * quantity) + addons_price
|
324 |
|
325 |
# Check if the menu item already exists in the cart for the user
|
326 |
+
soql = f"SELECT Id, Quantity__c, Add_Ons__c, Instructions__c, Price__c FROM Cart_Item__c WHERE Customer_Email__c = '{customer_email}' AND Name = '{menu_item['name']}' LIMIT 1"
|
327 |
+
existing_item = sf.query(soql)
|
328 |
|
329 |
+
if existing_item['records']: # If the item exists, update it
|
330 |
+
item_id = existing_item['records'][0]['Id']
|
331 |
+
existing_quantity = existing_item['records'][0]['Quantity__c']
|
332 |
+
existing_addons = existing_item['records'][0]['Add_Ons__c']
|
333 |
+
existing_instructions = existing_item['records'][0]['Instructions__c']
|
334 |
+
existing_price = existing_item['records'][0]['Price__c']
|
335 |
|
336 |
# Update quantity, addons, and instructions
|
337 |
new_quantity = existing_quantity + quantity
|
|
|
338 |
new_addons = (existing_addons or '') + (', ' + ingredient_names if ingredient_names else '')
|
339 |
new_instructions = (existing_instructions or '') + ('; ' + instructions if instructions else '')
|
340 |
+
|
341 |
# Calculate the new total price
|
342 |
updated_price = (base_price * new_quantity) + addons_price
|
343 |
|