lokesh341 commited on
Commit
74528d3
·
verified ·
1 Parent(s): 6b7317a

Update menu.py

Browse files
Files changed (1) hide show
  1. menu.py +148 -176
menu.py CHANGED
@@ -1,29 +1,35 @@
1
  from flask import Blueprint, render_template, request, session, jsonify, redirect, url_for
2
- from salesforce import get_salesforce_connection
3
  import os
 
 
 
 
 
 
4
 
5
  menu_blueprint = Blueprint('menu', __name__)
6
 
7
  # Initialize Salesforce connection
8
- sf = get_salesforce_connection()
 
 
 
 
9
 
10
- # Constants for video handling
11
  STATIC_DIR = os.path.join(os.path.dirname(__file__), 'static')
12
  PLACEHOLDER_VIDEO = 'placeholder.mp4'
13
  PLACEHOLDER_PATH = os.path.join(STATIC_DIR, PLACEHOLDER_VIDEO)
14
  SECTION_ORDER = ["Best Sellers", "Starters", "Biryanis", "Curries", "Breads", "Customized dish", "Apetizer", "Desserts", "Soft Drinks"]
15
 
16
- # Create placeholder video at startup if it doesn't exist
 
17
  if not os.path.exists(PLACEHOLDER_PATH):
18
- os.makedirs(STATIC_DIR, exist_ok=True) # Ensure static directory exists
19
  open(PLACEHOLDER_PATH, 'wb').close()
20
- print(f"Created placeholder video at {PLACEHOLDER_PATH}")
21
 
22
  def get_valid_video_path(item_name, video_url=None):
23
- """
24
- Get valid video path for item with placeholder fallback
25
- Priority: 1. Video1__c from Salesforce 2. placeholder.mp4
26
- """
27
  if video_url:
28
  if video_url.startswith(('http://', 'https://')):
29
  return video_url
@@ -31,11 +37,6 @@ def get_valid_video_path(item_name, video_url=None):
31
  return video_url
32
  elif video_url.startswith('069'):
33
  return f"https://yourdomain.my.salesforce.com/sfc/servlet.shepherd/version/download/{video_url}"
34
-
35
- if not os.path.exists(PLACEHOLDER_PATH):
36
- open(PLACEHOLDER_PATH, 'wb').close()
37
- print(f"Recreated missing placeholder video at {PLACEHOLDER_PATH}")
38
-
39
  return f"/static/{PLACEHOLDER_VIDEO}"
40
 
41
  @menu_blueprint.route("/menu", methods=["GET", "POST"])
@@ -46,119 +47,125 @@ def menu():
46
  if not user_email:
47
  user_email = request.args.get("email")
48
  user_name = request.args.get("name")
49
- if user_email:
50
  session['user_email'] = user_email
51
  session['user_name'] = user_name
52
  else:
 
53
  return redirect(url_for("login"))
54
  else:
55
  user_name = session.get('user_name')
56
 
57
  first_letter = user_name[0].upper() if user_name else "A"
58
-
59
- try:
60
- # Fetch user referral and reward points
61
- user_query = f"SELECT Referral__c, Reward_Points__c FROM Customer_Login__c WHERE Email__c = '{user_email}'"
62
- user_result = sf.query(user_query)
63
- if not user_result['records']:
64
- return redirect(url_for('login'))
65
- referral_code = user_result['records'][0].get('Referral__c', 'N/A')
66
- reward_points = user_result['records'][0].get('Reward_Points__c', 0)
67
-
68
- # Get cart item count
69
- cart_query = f"SELECT COUNT() FROM Cart_Item__c WHERE Customer_Email__c = '{user_email}'"
70
- cart_count_result = sf.query(cart_query)
71
- cart_item_count = cart_count_result['totalSize']
72
-
73
- # Query to fetch Menu_Item__c records
74
- menu_query = """
75
- SELECT Name, Price__c, Description__c, Image1__c, Image2__c,
76
- Veg_NonVeg__c, Section__c, Total_Ordered__c, Video1__c,
77
- Ingredients__c, NutritionalInfo__c, Allergens__c
78
- FROM Menu_Item__c
79
- """
80
- result = sf.query(menu_query)
81
- food_items = result.get('records', [])
82
-
83
- # Process menu items
84
- for item in food_items:
85
- item['Total_Ordered__c'] = item.get('Total_Ordered__c', 0)
86
- item['Video1__c'] = get_valid_video_path(item['Name'], item.get('Video1__c'))
87
- item['Ingredients__c'] = item.get('Ingredients__c', '')
88
- item['NutritionalInfo__c'] = item.get('NutritionalInfo__c', '')
89
- item['Allergens__c'] = item.get('Allergens__c', '')
90
-
91
- # Query to fetch Custom_Dish__c records
92
- custom_dish_query = """
93
- SELECT Name, Price__c, Description__c, Image1__c, Image2__c,
94
- Veg_NonVeg__c, Section__c, Total_Ordered__c,
95
- Ingredients__c, NutritionalInfo__c, Allergens__c
96
- FROM Custom_Dish__c
97
- WHERE CreatedDate >= LAST_N_DAYS:7
98
- """
99
- custom_dish_result = sf.query(custom_dish_query)
100
- custom_dishes = custom_dish_result.get('records', [])
101
-
102
- # Process custom dishes
103
- for item in custom_dishes:
104
- item['Total_Ordered__c'] = item.get('Total_Ordered__c', 0)
105
- item['Video1__c'] = get_valid_video_path(item['Name'])
106
- item['Ingredients__c'] = item.get('Ingredients__c', '')
107
- item['NutritionalInfo__c'] = item.get('NutritionalInfo__c', '')
108
- item['Allergens__c'] = item.get('Allergens__c', '')
109
-
110
- # Merge items
111
- all_items = food_items + custom_dishes
112
- ordered_menu = {section: [] for section in SECTION_ORDER}
113
-
114
- # Process best sellers
115
- best_sellers = sorted(all_items, key=lambda x: x.get("Total_Ordered__c", 0), reverse=True)
116
- if selected_category == "Veg":
117
- best_sellers = [item for item in best_sellers if item.get("Veg_NonVeg__c") in ["Veg", "both"]]
118
- elif selected_category == "Non veg":
119
- best_sellers = [item for item in best_sellers if item.get("Veg_NonVeg__c") in ["Non veg", "both"]]
120
- best_sellers = best_sellers[:4]
121
- if best_sellers:
122
- ordered_menu["Best Sellers"] = best_sellers
123
-
124
- # Organize other sections
125
- added_item_names = set()
126
- for item in all_items:
127
- section = item.get("Section__c", "Others")
128
- if section not in ordered_menu:
129
- ordered_menu[section] = []
130
- if item['Name'] in added_item_names:
131
- continue
132
- if selected_category == "Veg" and item.get("Veg_NonVeg__c") not in ["Veg", "both"]:
133
- continue
134
- if selected_category == "Non veg" and item.get("Veg_NonVeg__c") not in ["Non veg", "both"]:
135
- continue
136
- ordered_menu[section].append(item)
137
- added_item_names.add(item['Name'])
138
-
139
- ordered_menu = {k: v for k, v in ordered_menu.items() if v}
140
- categories = ["All", "Veg", "Non veg"]
141
-
142
- except Exception as e:
143
- print(f"Error fetching menu data: {str(e)}")
144
- ordered_menu = {section: [] for section in SECTION_ORDER}
 
 
 
 
 
 
 
145
  best_sellers = ["Chicken Biryani", "Paneer Butter Masala", "Veg Manchurian", "Prawn Fry"]
146
  ordered_menu["Best Sellers"] = [{
147
  "Name": name,
148
  "Price__c": "12.99",
149
  "Description__c": f"Popular {name}",
150
  "Image1__c": "/static/placeholder.jpg",
 
151
  "Video1__c": get_valid_video_path(name),
152
  "Total_Ordered__c": 100,
153
  "Veg_NonVeg__c": "Veg" if "Paneer" in name or "Veg" in name else "Non veg",
154
  "Ingredients__c": f"Sample ingredients for {name}",
155
  "NutritionalInfo__c": "Calories: 500, Protein: 20g",
156
- "Allergens__c": "Contains nuts, dairy"
 
157
  } for name in best_sellers]
158
- categories = ["All", "Veg", "Non veg"]
159
- referral_code = 'N/A'
160
- reward_points = 0
161
- cart_item_count = 0
162
 
163
  return render_template(
164
  "menu.html",
@@ -177,107 +184,72 @@ def get_addons():
177
  item_name = request.args.get('item_name')
178
  item_section = request.args.get('item_section')
179
  if not item_name or not item_section:
180
- return jsonify({"success": False, "error": "Item name and section are required."}), 400
181
  try:
182
- query = f"""
183
- SELECT Name, Customization_Type__c, Options__c, Max_Selections__c, Extra_Charge__c, Extra_Charge_Amount__c
184
- FROM Customization_Options__c
185
- WHERE Section__c = '{item_section}'
186
- """
187
  result = sf.query(query)
188
  addons = result.get('records', [])
189
- if not addons:
190
- return jsonify({"success": False, "error": "No customization options found."}), 404
191
- formatted_addons = []
192
- for addon in addons:
193
- options = addon.get("Options__c", "").split(", ") if addon.get("Options__c") else []
194
- formatted_addons.append({
195
- "name": addon["Name"],
196
- "type": addon["Customization_Type__c"],
197
- "options": options,
198
- "max_selections": addon.get("Max_Selections__c", 1),
199
- "extra_charge": addon.get("Extra_Charge__c", False),
200
- "extra_charge_amount": addon.get("Extra_Charge_Amount__c", 0)
201
- })
202
  return jsonify({"success": True, "addons": formatted_addons})
203
  except Exception as e:
204
- print(f"Error fetching addons: {str(e)}")
205
- return jsonify({"success": False, "error": "An error occurred while fetching addons."}), 500
206
 
207
  @menu_blueprint.route('/cart/add', methods=['POST'])
208
  def add_to_cart():
209
  try:
210
- data = request.json
211
- item_name = data.get('itemName', '').strip()
212
  item_price = float(data.get('itemPrice', 0))
213
- item_image = data.get('itemImage')
214
  addons = data.get('addons', [])
215
  instructions = data.get('instructions', '')
216
- category = data.get('category')
217
- section = data.get('section')
218
  quantity = int(data.get('quantity', 1))
219
  customer_email = session.get('user_email')
220
-
221
- if not item_name or not item_price or not customer_email:
222
- return jsonify({"success": False, "error": "Missing required fields."}), 400
223
 
224
- query = f"""
225
- SELECT Id, Quantity__c, Add_Ons__c, Add_Ons_Price__c, Instructions__c
226
- FROM Cart_Item__c
227
- WHERE Customer_Email__c = '{customer_email}' AND Name = '{item_name}'
228
- """
229
- result = sf.query(query)
230
- cart_items = result.get("records", [])
231
 
232
  addons_price = sum(float(addon['price']) for addon in addons)
233
- new_addons = "; ".join([f"{addon['name']} (${addon['price']})" for addon in addons]) if addons else "None"
 
234
 
235
- if cart_items:
236
- cart_item_id = cart_items[0]['Id']
237
- existing_quantity = cart_items[0]['Quantity__c']
238
- existing_addons = cart_items[0].get('Add_Ons__c', "None")
239
- existing_addons_price = cart_items[0].get('Add_Ons_Price__c', 0)
240
- existing_instructions = cart_items[0].get('Instructions__c', "")
241
-
242
- combined_addons = existing_addons if existing_addons != "None" else ""
243
- if new_addons and new_addons != "None":
244
- combined_addons = f"{combined_addons}; {new_addons}".strip("; ")
245
- combined_instructions = f"{existing_instructions} | {instructions}".strip(" | ") if instructions else existing_instructions
246
-
247
- combined_addons_list = combined_addons.split("; ")
248
- combined_addons_price = sum(float(a.split("($")[1][:-1]) for a in combined_addons_list if "($" in a)
249
-
250
- sf.Cart_Item__c.update(cart_item_id, {
251
- "Quantity__c": existing_quantity + quantity,
252
- "Add_Ons__c": combined_addons,
253
- "Add_Ons_Price__c": combined_addons_price,
254
- "Instructions__c": combined_instructions,
255
- "Price__c": (existing_quantity + quantity) * item_price + combined_addons_price,
256
- "Category__c": category,
257
- "Section__c": section
258
  })
259
  else:
260
- total_price = item_price * quantity + addons_price
261
  sf.Cart_Item__c.create({
262
  "Name": item_name,
263
  "Price__c": total_price,
264
  "Base_Price__c": item_price,
265
  "Quantity__c": quantity,
266
  "Add_Ons_Price__c": addons_price,
267
- "Add_Ons__c": new_addons,
268
  "Image1__c": item_image,
269
  "Customer_Email__c": customer_email,
270
  "Instructions__c": instructions,
271
  "Category__c": category,
272
  "Section__c": section
273
  })
274
-
275
  cart_query = f"SELECT Quantity__c FROM Cart_Item__c WHERE Customer_Email__c = '{customer_email}'"
276
  cart_result = sf.query(cart_query)
277
  cart = [{"quantity": item["Quantity__c"]} for item in cart_result.get("records", [])]
278
-
279
- return jsonify({"success": True, "message": "Item added to cart.", "cart": cart})
280
-
281
  except Exception as e:
282
- print(f"Error adding to cart: {str(e)}")
283
- return jsonify({"success": False, "error": "Failed to add item to cart."}), 500
 
1
  from flask import Blueprint, render_template, request, session, jsonify, redirect, url_for
 
2
  import os
3
+ from salesforce import get_salesforce_connection # Assuming this is your Salesforce connector
4
+ import logging
5
+
6
+ # Setup logging for debugging
7
+ logging.basicConfig(level=logging.DEBUG)
8
+ logger = logging.getLogger(__name__)
9
 
10
  menu_blueprint = Blueprint('menu', __name__)
11
 
12
  # Initialize Salesforce connection
13
+ try:
14
+ sf = get_salesforce_connection()
15
+ except Exception as e:
16
+ logger.error(f"Failed to initialize Salesforce connection: {str(e)}")
17
+ sf = None
18
 
19
+ # Constants
20
  STATIC_DIR = os.path.join(os.path.dirname(__file__), 'static')
21
  PLACEHOLDER_VIDEO = 'placeholder.mp4'
22
  PLACEHOLDER_PATH = os.path.join(STATIC_DIR, PLACEHOLDER_VIDEO)
23
  SECTION_ORDER = ["Best Sellers", "Starters", "Biryanis", "Curries", "Breads", "Customized dish", "Apetizer", "Desserts", "Soft Drinks"]
24
 
25
+ # Ensure static directory and placeholder exist
26
+ os.makedirs(STATIC_DIR, exist_ok=True)
27
  if not os.path.exists(PLACEHOLDER_PATH):
 
28
  open(PLACEHOLDER_PATH, 'wb').close()
29
+ logger.info(f"Created placeholder video at {PLACEHOLDER_PATH}")
30
 
31
  def get_valid_video_path(item_name, video_url=None):
32
+ """Return a valid video URL with fallback to placeholder."""
 
 
 
33
  if video_url:
34
  if video_url.startswith(('http://', 'https://')):
35
  return video_url
 
37
  return video_url
38
  elif video_url.startswith('069'):
39
  return f"https://yourdomain.my.salesforce.com/sfc/servlet.shepherd/version/download/{video_url}"
 
 
 
 
 
40
  return f"/static/{PLACEHOLDER_VIDEO}"
41
 
42
  @menu_blueprint.route("/menu", methods=["GET", "POST"])
 
47
  if not user_email:
48
  user_email = request.args.get("email")
49
  user_name = request.args.get("name")
50
+ if user_email and user_name:
51
  session['user_email'] = user_email
52
  session['user_name'] = user_name
53
  else:
54
+ logger.warning("No user email in session or args, redirecting to login")
55
  return redirect(url_for("login"))
56
  else:
57
  user_name = session.get('user_name')
58
 
59
  first_letter = user_name[0].upper() if user_name else "A"
60
+ ordered_menu = {section: [] for section in SECTION_ORDER}
61
+ categories = ["All", "Veg", "Non veg"]
62
+ referral_code = 'N/A'
63
+ reward_points = 0
64
+ cart_item_count = 0
65
+
66
+ if sf:
67
+ try:
68
+ # Fetch user data
69
+ user_query = f"SELECT Referral__c, Reward_Points__c FROM Customer_Login__c WHERE Email__c = '{user_email}'"
70
+ user_result = sf.query(user_query)
71
+ if not user_result.get('records'):
72
+ logger.warning(f"No user found for email: {user_email}")
73
+ return redirect(url_for('login'))
74
+ user_record = user_result['records'][0]
75
+ referral_code = user_record.get('Referral__c', 'N/A')
76
+ reward_points = user_record.get('Reward_Points__c', 0)
77
+
78
+ # Cart count
79
+ cart_query = f"SELECT COUNT() FROM Cart_Item__c WHERE Customer_Email__c = '{user_email}'"
80
+ cart_count_result = sf.query(cart_query)
81
+ cart_item_count = cart_count_result.get('totalSize', 0)
82
+
83
+ # Fetch Menu_Item__c
84
+ menu_query = """
85
+ SELECT Name, Price__c, Description__c, Image1__c, Image2__c,
86
+ Veg_NonVeg__c, Section__c, Total_Ordered__c, Video1__c,
87
+ Ingredients__c, NutritionalInfo__c, Allergens__c
88
+ FROM Menu_Item__c
89
+ """
90
+ menu_result = sf.query(menu_query)
91
+ food_items = menu_result.get('records', [])
92
+ logger.debug(f"Fetched {len(food_items)} menu items")
93
+
94
+ # Process menu items
95
+ for item in food_items:
96
+ item['Total_Ordered__c'] = item.get('Total_Ordered__c', 0)
97
+ item['Video1__c'] = get_valid_video_path(item['Name'], item.get('Video1__c'))
98
+ item['Ingredients__c'] = item.get('Ingredients__c', '')
99
+ item['NutritionalInfo__c'] = item.get('NutritionalInfo__c', '')
100
+ item['Allergens__c'] = item.get('Allergens__c', '')
101
+
102
+ # Fetch Custom_Dish__c
103
+ custom_query = """
104
+ SELECT Name, Price__c, Description__c, Image1__c, Image2__c,
105
+ Veg_NonVeg__c, Section__c, Total_Ordered__c,
106
+ Ingredients__c, NutritionalInfo__c, Allergens__c
107
+ FROM Custom_Dish__c
108
+ WHERE CreatedDate >= LAST_N_DAYS:7
109
+ """
110
+ custom_result = sf.query(custom_query)
111
+ custom_dishes = custom_result.get('records', [])
112
+ logger.debug(f"Fetched {len(custom_dishes)} custom dishes")
113
+
114
+ # Process custom dishes
115
+ for item in custom_dishes:
116
+ item['Total_Ordered__c'] = item.get('Total_Ordered__c', 0)
117
+ item['Video1__c'] = get_valid_video_path(item['Name'])
118
+ item['Ingredients__c'] = item.get('Ingredients__c', '')
119
+ item['NutritionalInfo__c'] = item.get('NutritionalInfo__c', '')
120
+ item['Allergens__c'] = item.get('Allergens__c', '')
121
+
122
+ # Combine and organize items
123
+ all_items = food_items + custom_dishes
124
+ best_sellers = sorted(all_items, key=lambda x: x.get("Total_Ordered__c", 0), reverse=True)
125
+ if selected_category == "Veg":
126
+ best_sellers = [item for item in best_sellers if item.get("Veg_NonVeg__c") in ["Veg", "both"]]
127
+ elif selected_category == "Non veg":
128
+ best_sellers = [item for item in best_sellers if item.get("Veg_NonVeg__c") in ["Non veg", "both"]]
129
+ ordered_menu["Best Sellers"] = best_sellers[:4]
130
+
131
+ added_item_names = set()
132
+ for item in all_items:
133
+ section = item.get("Section__c", "Others")
134
+ if section not in ordered_menu:
135
+ ordered_menu[section] = []
136
+ if item['Name'] in added_item_names:
137
+ continue
138
+ if selected_category == "Veg" and item.get("Veg_NonVeg__c") not in ["Veg", "both"]:
139
+ continue
140
+ if selected_category == "Non veg" and item.get("Veg_NonVeg__c") not in ["Non veg", "both"]:
141
+ continue
142
+ ordered_menu[section].append(item)
143
+ added_item_names.add(item['Name'])
144
+
145
+ ordered_menu = {k: v for k, v in ordered_menu.items() if v}
146
+ logger.debug(f"Final ordered_menu: {ordered_menu.keys()}")
147
+
148
+ except Exception as e:
149
+ logger.error(f"Error in menu processing: {str(e)}")
150
+
151
+ # Fallback data if Salesforce fails or no items
152
+ if not ordered_menu["Best Sellers"]:
153
+ logger.warning("No items fetched, using fallback data")
154
  best_sellers = ["Chicken Biryani", "Paneer Butter Masala", "Veg Manchurian", "Prawn Fry"]
155
  ordered_menu["Best Sellers"] = [{
156
  "Name": name,
157
  "Price__c": "12.99",
158
  "Description__c": f"Popular {name}",
159
  "Image1__c": "/static/placeholder.jpg",
160
+ "Image2__c": "/static/placeholder.jpg",
161
  "Video1__c": get_valid_video_path(name),
162
  "Total_Ordered__c": 100,
163
  "Veg_NonVeg__c": "Veg" if "Paneer" in name or "Veg" in name else "Non veg",
164
  "Ingredients__c": f"Sample ingredients for {name}",
165
  "NutritionalInfo__c": "Calories: 500, Protein: 20g",
166
+ "Allergens__c": "Contains nuts, dairy",
167
+ "Section__c": "Best Sellers"
168
  } for name in best_sellers]
 
 
 
 
169
 
170
  return render_template(
171
  "menu.html",
 
184
  item_name = request.args.get('item_name')
185
  item_section = request.args.get('item_section')
186
  if not item_name or not item_section:
187
+ return jsonify({"success": False, "error": "Item name and section required"}), 400
188
  try:
189
+ query = f"SELECT Name, Customization_Type__c, Options__c, Max_Selections__c, Extra_Charge__c, Extra_Charge_Amount__c FROM Customization_Options__c WHERE Section__c = '{item_section}'"
 
 
 
 
190
  result = sf.query(query)
191
  addons = result.get('records', [])
192
+ formatted_addons = [{
193
+ "name": addon["Name"],
194
+ "type": addon.get("Customization_Type__c", ""),
195
+ "options": addon.get("Options__c", "").split(", ") if addon.get("Options__c") else [],
196
+ "max_selections": addon.get("Max_Selections__c", 1),
197
+ "extra_charge": addon.get("Extra_Charge__c", False),
198
+ "extra_charge_amount": addon.get("Extra_Charge_Amount__c", 0)
199
+ } for addon in addons]
 
 
 
 
 
200
  return jsonify({"success": True, "addons": formatted_addons})
201
  except Exception as e:
202
+ logger.error(f"Error fetching addons: {str(e)}")
203
+ return jsonify({"success": False, "error": "Failed to fetch addons"}), 500
204
 
205
  @menu_blueprint.route('/cart/add', methods=['POST'])
206
  def add_to_cart():
207
  try:
208
+ data = request.get_json()
209
+ item_name = data.get('itemName', '')
210
  item_price = float(data.get('itemPrice', 0))
211
+ item_image = data.get('itemImage', '/static/placeholder.jpg')
212
  addons = data.get('addons', [])
213
  instructions = data.get('instructions', '')
214
+ category = data.get('category', '')
215
+ section = data.get('section', '')
216
  quantity = int(data.get('quantity', 1))
217
  customer_email = session.get('user_email')
 
 
 
218
 
219
+ if not item_name or not customer_email:
220
+ return jsonify({"success": False, "error": "Missing item name or user email"}), 400
 
 
 
 
 
221
 
222
  addons_price = sum(float(addon['price']) for addon in addons)
223
+ addons_str = "; ".join([f"{addon['name']} (${addon['price']})" for addon in addons]) if addons else "None"
224
+ total_price = item_price * quantity + addons_price
225
 
226
+ query = f"SELECT Id, Quantity__c FROM Cart_Item__c WHERE Customer_Email__c = '{customer_email}' AND Name = '{item_name}'"
227
+ result = sf.query(query)
228
+ if result.get('records'):
229
+ cart_item = result['records'][0]
230
+ sf.Cart_Item__c.update(cart_item['Id'], {
231
+ "Quantity__c": cart_item['Quantity__c'] + quantity,
232
+ "Price__c": (cart_item['Quantity__c'] + quantity) * item_price + addons_price
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  })
234
  else:
 
235
  sf.Cart_Item__c.create({
236
  "Name": item_name,
237
  "Price__c": total_price,
238
  "Base_Price__c": item_price,
239
  "Quantity__c": quantity,
240
  "Add_Ons_Price__c": addons_price,
241
+ "Add_Ons__c": addons_str,
242
  "Image1__c": item_image,
243
  "Customer_Email__c": customer_email,
244
  "Instructions__c": instructions,
245
  "Category__c": category,
246
  "Section__c": section
247
  })
248
+
249
  cart_query = f"SELECT Quantity__c FROM Cart_Item__c WHERE Customer_Email__c = '{customer_email}'"
250
  cart_result = sf.query(cart_query)
251
  cart = [{"quantity": item["Quantity__c"]} for item in cart_result.get("records", [])]
252
+ return jsonify({"success": True, "cart": cart})
 
 
253
  except Exception as e:
254
+ logger.error(f"Error adding to cart: {str(e)}")
255
+ return jsonify({"success": False, "error": "Failed to add to cart"}), 500