nagasurendra commited on
Commit
b6962ca
·
verified ·
1 Parent(s): b487b59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py CHANGED
@@ -178,6 +178,60 @@ def submit_customization_ingredients():
178
  except Exception as e:
179
  logger.error(f"Failed to submit: {str(e)}")
180
  return jsonify({"error": f"Failed to submit: {str(e)}"}), 500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
 
182
  if __name__ == '__main__':
183
  app.run(debug=True, host='0.0.0.0', port=7860)
 
178
  except Exception as e:
179
  logger.error(f"Failed to submit: {str(e)}")
180
  return jsonify({"error": f"Failed to submit: {str(e)}"}), 500
181
+ @app.route('/cart/add_custom', methods=['POST'])
182
+ def add_custom_to_cart():
183
+ try:
184
+ global sf
185
+ if not sf:
186
+ sf = get_salesforce_connection()
187
+ if not sf:
188
+ return jsonify({"success": False, "error": "Salesforce connection failed"}), 500
189
+
190
+ data = request.json
191
+ menu_item = data.get('menu_item', {})
192
+ ingredients = data.get('ingredients', [])
193
+ instructions = data.get('instructions', '')
194
+
195
+ //customer_email = session.get('user_email')
196
+
197
+ //if not menu_item or not customer_email:
198
+ if not menu_item:
199
+ return jsonify({"success": False, "error": "Missing menu item or customer email"}), 400
200
+
201
+ item_name = menu_item.get('name', '').strip()
202
+ item_price = float(menu_item.get('price', 0))
203
+ item_image = menu_item.get('image_url', '')
204
+ category = menu_item.get('category', '')
205
+ section = menu_item.get('section', '')
206
+ veg_nonveg = menu_item.get('veg_nonveg', '')
207
+
208
+ # Combine addons
209
+ addons_str = "; ".join([f"{i['name']} (${i.get('price', 0)})" for i in ingredients]) if ingredients else "None"
210
+ addons_price = sum(float(i.get('price', 0)) for i in ingredients)
211
+
212
+ total_price = item_price + addons_price
213
+
214
+ # Create new cart record
215
+ sf.Cart_Item__c.create({
216
+ "Name": item_name,
217
+ "Base_Price__c": item_price,
218
+ "Price__c": total_price,
219
+ "Quantity__c": 1,
220
+ "Add_Ons__c": addons_str,
221
+ "Add_Ons_Price__c": addons_price,
222
+ "Image1__c": item_image,
223
+ "Customer_Email__c": customer_email,
224
+ "Instructions__c": instructions,
225
+ "Category__c": category or veg_nonveg,
226
+ "Section__c": section
227
+ })
228
+
229
+ return jsonify({"success": True, "message": f"'{item_name}' added to cart with custom ingredients."})
230
+
231
+ except Exception as e:
232
+ print(f"Error in custom add to cart: {str(e)}")
233
+ return jsonify({"success": False, "error": f"Failed to add item: {str(e)}"}), 500
234
+
235
 
236
  if __name__ == '__main__':
237
  app.run(debug=True, host='0.0.0.0', port=7860)