lokeshloki143 commited on
Commit
73513f6
·
verified ·
1 Parent(s): 0ea0767

Update cart.py

Browse files
Files changed (1) hide show
  1. cart.py +95 -154
cart.py CHANGED
@@ -9,7 +9,6 @@ cart_blueprint = Blueprint('cart', __name__)
9
  def sanitize_input(value):
10
  """Remove potentially dangerous characters for SOQL injection."""
11
  if value:
12
- # Remove quotes, semicolons, and other dangerous characters
13
  value = re.sub(r'[;\'"\\]', '', value)
14
  return value
15
 
@@ -20,114 +19,87 @@ def cart():
20
  return redirect(url_for("login"))
21
 
22
  try:
23
- # Sanitize email input
24
  sanitized_email = sanitize_input(email)
25
- # Fetch cart items with Category and Section
26
  result = sf.query(f"""
27
  SELECT Name, Price__c, Quantity__c, Add_Ons__c, Add_Ons_Price__c, Image1__c, Instructions__c, Category__c, Section__c
28
  FROM Cart_Item__c
29
  WHERE Customer_Email__c = '{sanitized_email}'
30
  """)
31
  cart_items = result.get("records", [])
32
-
33
  subtotal = sum(item['Price__c'] for item in cart_items)
34
 
35
- # Fetch reward points
36
- customer_result = sf.query(f"""
37
- SELECT Reward_Points__c
38
- FROM Customer_Login__c
39
- WHERE Email__c = '{sanitized_email}'
40
- """)
41
- reward_points = customer_result['records'][0].get('Reward_Points__c', 0) if customer_result['records'] else 0
42
 
43
- # Fetch coupons for the user
44
- coupon_result = sf.query(f"""
45
- SELECT Coupon_Code__c FROM Referral_Coupon__c WHERE Referral_Email__c = '{sanitized_email}'
46
- """)
47
- if coupon_result["records"]:
48
- raw_coupons = coupon_result["records"][0].get("Coupon_Code__c", "")
49
- coupons = raw_coupons.split("\n") if raw_coupons else []
50
- else:
51
- coupons = []
52
 
53
- # Initialize suggestions as an empty list
54
- suggestions = []
 
 
 
55
 
56
- # If there are items in the cart, fetch suggestions
57
- if cart_items:
58
- # Get the category and section of the first item in the cart
59
- first_item = cart_items[0]
60
- item_category = first_item.get('Category__c', 'All')
61
- item_section = first_item.get('Section__c', 'Biryanis')
62
-
63
- # Define section-to-complementary section mapping
64
- complementary_sections = {
65
- 'Breads': ['Curries', 'Biryanis', 'Starters'],
66
- 'Biryanis': ['Curries', 'Starters', 'Desserts'],
67
- 'Curries': ['Biryanis', 'Breads', 'Starters'],
68
- 'Starters': ['Biryanis', 'Curries', 'Desserts'],
69
- 'Desserts': ['Biryanis', 'Curries', 'Soft Drinks'],
70
- 'Soft Drinks': ['Starters', 'Biryanis', 'Curries']
71
- }
72
-
73
- # Get the complementary sections
74
- suggested_sections = complementary_sections.get(item_section, [])
75
-
76
- # Fetch suggestions from the complementary sections
77
- try:
78
- for suggested_section in suggested_sections:
79
- if item_category == "All":
80
- query = f"""
81
- SELECT Name, Price__c, Image1__c
82
- FROM Menu_Item__c
83
- WHERE Section__c = '{sanitize_input(suggested_section)}'
84
- AND (Veg_NonVeg__c = 'Veg' OR Veg_NonVeg__c = 'Non veg')
85
- LIMIT 4
86
- """
87
- else:
88
- query = f"""
89
- SELECT Name, Price__c, Image1__c
90
- FROM Menu_Item__c
91
- WHERE Section__c = '{sanitize_input(suggested_section)}'
92
- AND Veg_NonVeg__c = '{sanitize_input(item_category)}'
93
- LIMIT 4
94
- """
95
- suggestion_result = sf.query(query)
96
- suggestions.extend(suggestion_result.get("records", []))
97
-
98
- # Limit to 4 suggestions
99
- if len(suggestions) > 4:
100
- suggestions = suggestions[:4]
101
-
102
- except Exception as e:
103
- print(f"Error fetching suggestions: {e}")
104
 
105
  return render_template(
106
- "cart.html",
107
  cart_items=cart_items,
108
  subtotal=subtotal,
109
- reward_points=reward_points,
110
- customer_email=email,
111
- coupons=coupons,
112
- suggestions=suggestions
113
  )
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  except Exception as e:
116
  print(f"Error fetching cart items: {e}")
117
- return render_template("cart.html", cart_items=[], subtotal=0, reward_points=0, coupons=[], suggestions=[])
118
 
119
  @cart_blueprint.route("/fetch_menu_items", methods=["GET"])
120
  def fetch_menu_items():
121
  try:
122
- # Get query parameters for filtering (optional)
123
  category = request.args.get('category', 'All')
124
  section = request.args.get('section', '')
125
-
126
- # Sanitize inputs
127
  category = sanitize_input(category)
128
  section = sanitize_input(section)
129
 
130
- # Build SOQL query (removed Active__c condition)
131
  query = """
132
  SELECT Name, Price__c, Image1__c, Veg_NonVeg__c, Section__c
133
  FROM Menu_Item__c
@@ -147,10 +119,28 @@ def fetch_menu_items():
147
  print(f"Error fetching menu items: {str(e)}")
148
  return jsonify({"success": False, "error": str(e)}), 500
149
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  @cart_blueprint.route("/add_suggestion_to_cart", methods=["POST"])
151
  def add_suggestion_to_cart():
152
  try:
153
- # Get data from the request
154
  data = request.get_json()
155
  item_name = sanitize_input(data.get('item_name').strip())
156
  item_price = data.get('item_price')
@@ -158,24 +148,29 @@ def add_suggestion_to_cart():
158
  customer_email = sanitize_input(data.get('customer_email'))
159
  addons = data.get('addons', [])
160
  instructions = sanitize_input(data.get('instructions', ""))
 
 
 
 
 
 
 
 
 
161
 
162
- # Validate inputs
163
  if not all([item_name, item_price, customer_email]):
164
  return jsonify({"success": False, "error": "Missing required fields"}), 400
165
 
166
- # Process add-ons
167
  addons_price = 0
168
  addons_string = ", ".join(addons) if addons else "None"
169
 
170
  if addons:
171
- # Assuming addons are in format "Name ($Price)"
172
  addons_price = sum(
173
  float(addon.split("($")[1][:-1]) for addon in addons if "($" in addon
174
  )
175
 
176
- # Check if item exists in cart
177
  query = f"""
178
- SELECT Id, Quantity__c, Add_Ons__c, Add_Ons_Price__c, Instructions__c
179
  FROM Cart_Item__c
180
  WHERE Customer_Email__c = '{customer_email}' AND Name = '{item_name}'
181
  """
@@ -183,42 +178,40 @@ def add_suggestion_to_cart():
183
  cart_items = result.get("records", [])
184
 
185
  if cart_items:
186
- # Update existing item
187
  cart_item_id = cart_items[0]['Id']
188
  existing_quantity = cart_items[0]['Quantity__c']
189
  existing_addons = cart_items[0].get('Add_Ons__c', "None")
190
  existing_addons_price = cart_items[0].get('Add_Ons_Price__c', 0)
191
  existing_instructions = cart_items[0].get('Instructions__c', "")
 
192
 
193
- # Combine add-ons
194
  combined_addons = existing_addons if existing_addons != "None" else ""
195
  if addons:
196
  combined_addons = f"{combined_addons}, {addons_string}".strip(", ")
197
 
198
- # Combine instructions
199
  combined_instructions = existing_instructions
200
  if instructions:
201
  combined_instructions = f"{combined_instructions} | {instructions}".strip(" | ")
202
 
203
- combined_addons_price = existing_addons_price + addons_price
 
 
204
 
205
- # Update cart item
206
  sf.Cart_Item__c.update(cart_item_id, {
207
- "Quantity__c": existing_quantity + 1,
208
  "Add_Ons__c": combined_addons if combined_addons else "None",
209
- "Add_Ons_Price__c": combined_addons_price,
210
  "Instructions__c": combined_instructions,
211
- "Price__c": (existing_quantity + 1) * float(item_price) + combined_addons_price
212
  })
213
  else:
214
- # Create new cart item
215
- total_price = float(item_price) + addons_price
216
  sf.Cart_Item__c.create({
217
  "Name": item_name,
218
  "Price__c": total_price,
219
  "Base_Price__c": item_price,
220
- "Quantity__c": 1,
221
- "Add_Ons_Price__c": addons_price,
222
  "Add_Ons__c": addons_string,
223
  "Image1__c": item_image,
224
  "Customer_Email__c": customer_email,
@@ -236,7 +229,7 @@ def remove_cart_item(item_name):
236
  try:
237
  customer_email = session.get('user_email')
238
  if not customer_email:
239
- return jsonify({'success': False, 'message': 'User email not found. Please log in again.'}), 400
240
 
241
  sanitized_email = sanitize_input(customer_email)
242
  sanitized_item_name = sanitize_input(item_name)
@@ -258,7 +251,6 @@ def remove_cart_item(item_name):
258
 
259
  @cart_blueprint.route("/update_quantity", methods=["POST"])
260
  def update_quantity():
261
- print("Handling update_quantity request...")
262
  data = request.json
263
  email = sanitize_input(data.get('email'))
264
  item_name = sanitize_input(data.get('item_name'))
@@ -312,11 +304,6 @@ def checkout():
312
 
313
  try:
314
  sanitized_email = sanitize_input(email)
315
- # Fetch selected coupon
316
- data = request.json
317
- selected_coupon = data.get("selectedCoupon", "").strip() if data.get("selectedCoupon") else None
318
-
319
- # Fetch cart items
320
  result = sf.query(f"""
321
  SELECT Id, Name, Price__c, Add_Ons_Price__c, Quantity__c, Add_Ons__c, Instructions__c, Image1__c
322
  FROM Cart_Item__c
@@ -327,15 +314,8 @@ def checkout():
327
  return jsonify({"success": False, "message": "Cart is empty"}), 400
328
 
329
  subtotal = sum(item['Price__c'] for item in cart_items)
330
- discount = 0
331
 
332
- # Apply coupon if selected
333
- if selected_coupon:
334
- discount = subtotal * 0.10 # 10% discount
335
-
336
- total = subtotal - discount
337
-
338
- # Prepare cart items for response
339
  bill_items = [
340
  {
341
  "name": item['Name'],
@@ -347,7 +327,6 @@ def checkout():
347
  } for item in cart_items
348
  ]
349
 
350
- # Fetch menu items for "Anything else you want?" (removed Active__c condition)
351
  menu_query = """
352
  SELECT Name, Price__c, Image1__c, Veg_NonVeg__c, Section__c
353
  FROM Menu_Item__c
@@ -361,9 +340,7 @@ def checkout():
361
  "cart": {
362
  "items": bill_items,
363
  "subtotal": subtotal,
364
- "discount": discount,
365
- "total": total,
366
- "selected_coupon": selected_coupon
367
  },
368
  "menu_items": menu_items
369
  })
@@ -388,7 +365,6 @@ def submit_order():
388
  if not cart:
389
  return jsonify({"success": False, "message": "Cart data is required"}), 400
390
 
391
- # Fetch cart items to validate
392
  result = sf.query(f"""
393
  SELECT Id, Name, Price__c, Add_Ons_Price__c, Quantity__c, Add_Ons__c, Instructions__c, Image1__c
394
  FROM Cart_Item__c
@@ -399,40 +375,8 @@ def submit_order():
399
  return jsonify({"success": False, "message": "Cart is empty"}), 400
400
 
401
  subtotal = cart.get("subtotal")
402
- discount = cart.get("discount", 0)
403
  total = cart.get("total")
404
- selected_coupon = cart.get("selected_coupon")
405
-
406
- # Handle coupon redemption
407
- if selected_coupon:
408
- coupon_query = sf.query(f"""
409
- SELECT Id, Coupon_Code__c FROM Referral_Coupon__c WHERE Referral_Email__c = '{sanitized_email}'
410
- """)
411
- if coupon_query["records"]:
412
- referral_coupon_id = coupon_query["records"][0]["Id"]
413
- existing_coupons = coupon_query["records"][0]["Coupon_Code__c"].split("\n")
414
- updated_coupons = [coupon for coupon in existing_coupons if coupon.strip() != selected_coupon]
415
- updated_coupons_str = "\n".join(updated_coupons).strip() or None
416
- sf.Referral_Coupon__c.update(referral_coupon_id, {
417
- "Coupon_Code__c": updated_coupons_str
418
- })
419
-
420
- # Add reward points if no coupon
421
- if not selected_coupon:
422
- reward_points_to_add = subtotal * 0.10
423
- customer_record = sf.query(f"""
424
- SELECT Id, Reward_Points__c FROM Customer_Login__c
425
- WHERE Email__c = '{sanitized_email}'
426
- """)
427
- if customer_record["records"]:
428
- customer = customer_record["records"][0]
429
- current_reward_points = customer.get("Reward_Points__c", 0)
430
- new_reward_points = current_reward_points + reward_points_to_add
431
- sf.Customer_Login__c.update(customer["Id"], {
432
- "Reward_Points__c": new_reward_points
433
- })
434
-
435
- # Prepare order details
436
  order_details = "\n".join(
437
  f"{item['Name']} x{item['Quantity__c']} | Add-Ons: {item.get('Add_Ons__c', 'None')} | "
438
  f"Instructions: {item.get('Instructions__c', 'None')} | "
@@ -440,7 +384,6 @@ def submit_order():
440
  for item in cart_items
441
  )
442
 
443
- # Fetch Customer ID
444
  customer_query = sf.query(f"""
445
  SELECT Id FROM Customer_Login__c
446
  WHERE Email__c = '{sanitized_email}'
@@ -454,7 +397,6 @@ def submit_order():
454
  "Customer_Name__c": user_id,
455
  "Customer_Email__c": email,
456
  "Total_Amount__c": subtotal,
457
- "Discount__c": discount,
458
  "Total_Bill__c": total,
459
  "Order_Status__c": "Pending",
460
  "Customer2__c": customer_id,
@@ -463,7 +405,6 @@ def submit_order():
463
  }
464
  order_response = sf.Order__c.create(order_data)
465
 
466
- # Delete cart items
467
  if order_response:
468
  for item in cart_items:
469
  sf.Cart_Item__c.delete(item["Id"])
 
9
  def sanitize_input(value):
10
  """Remove potentially dangerous characters for SOQL injection."""
11
  if value:
 
12
  value = re.sub(r'[;\'"\\]', '', value)
13
  return value
14
 
 
19
  return redirect(url_for("login"))
20
 
21
  try:
 
22
  sanitized_email = sanitize_input(email)
 
23
  result = sf.query(f"""
24
  SELECT Name, Price__c, Quantity__c, Add_Ons__c, Add_Ons_Price__c, Image1__c, Instructions__c, Category__c, Section__c
25
  FROM Cart_Item__c
26
  WHERE Customer_Email__c = '{sanitized_email}'
27
  """)
28
  cart_items = result.get("records", [])
 
29
  subtotal = sum(item['Price__c'] for item in cart_items)
30
 
31
+ return render_template(
32
+ "cart.html",
33
+ cart_items=cart_items,
34
+ subtotal=subtotal,
35
+ customer_email=email
36
+ )
 
37
 
38
+ except Exception as e:
39
+ print(f"Error fetching cart items: {e}")
40
+ return render_template("cart.html", cart_items=[], subtotal=0, customer_email=email)
 
 
 
 
 
 
41
 
42
+ @cart_blueprint.route("/bill", methods=["GET"])
43
+ def bill():
44
+ email = session.get('user_email')
45
+ if not email:
46
+ return redirect(url_for("login"))
47
 
48
+ try:
49
+ sanitized_email = sanitize_input(email)
50
+ result = sf.query(f"""
51
+ SELECT Name, Price__c, Quantity__c, Add_Ons__c, Add_Ons_Price__c, Image1__c, Instructions__c
52
+ FROM Cart_Item__c
53
+ WHERE Customer_Email__c = '{sanitized_email}'
54
+ """)
55
+ cart_items = result.get("records", [])
56
+ subtotal = sum(item['Price__c'] for item in cart_items)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
  return render_template(
59
+ "bill.html",
60
  cart_items=cart_items,
61
  subtotal=subtotal,
62
+ customer_email=email
 
 
 
63
  )
64
 
65
+ except Exception as e:
66
+ print(f"Error fetching bill items: {e}")
67
+ return render_template("bill.html", cart_items=[], subtotal=0, customer_email=email)
68
+
69
+ @cart_blueprint.route("/bill/fetch_cart", methods=["GET"])
70
+ def fetch_cart():
71
+ email = session.get('user_email')
72
+ if not email:
73
+ return jsonify({"success": False, "error": "User not logged in"}), 401
74
+
75
+ try:
76
+ sanitized_email = sanitize_input(email)
77
+ result = sf.query(f"""
78
+ SELECT Name, Price__c, Quantity__c, Add_Ons__c, Add_Ons_Price__c, Image1__c, Instructions__c
79
+ FROM Cart_Item__c
80
+ WHERE Customer_Email__c = '{sanitized_email}'
81
+ """)
82
+ cart_items = result.get("records", [])
83
+ subtotal = sum(item['Price__c'] for item in cart_items)
84
+
85
+ return jsonify({
86
+ "success": True,
87
+ "cart_items": cart_items,
88
+ "subtotal": subtotal
89
+ })
90
+
91
  except Exception as e:
92
  print(f"Error fetching cart items: {e}")
93
+ return jsonify({"success": False, "error": str(e)}), 500
94
 
95
  @cart_blueprint.route("/fetch_menu_items", methods=["GET"])
96
  def fetch_menu_items():
97
  try:
 
98
  category = request.args.get('category', 'All')
99
  section = request.args.get('section', '')
 
 
100
  category = sanitize_input(category)
101
  section = sanitize_input(section)
102
 
 
103
  query = """
104
  SELECT Name, Price__c, Image1__c, Veg_NonVeg__c, Section__c
105
  FROM Menu_Item__c
 
119
  print(f"Error fetching menu items: {str(e)}")
120
  return jsonify({"success": False, "error": str(e)}), 500
121
 
122
+ @cart_blueprint.route("/fetch_add_ons", methods=["GET"])
123
+ def fetch_add_ons():
124
+ try:
125
+ query = """
126
+ SELECT Name, Price__c
127
+ FROM Add_On__c
128
+ WHERE Active__c = true
129
+ LIMIT 10
130
+ """
131
+ result = sf.query(query)
132
+ add_ons = [
133
+ {"name": f"{addon['Name']} (${addon['Price__c']:.2f})", "price": addon['Price__c']}
134
+ for addon in result.get("records", [])
135
+ ]
136
+ return jsonify({"success": True, "add_ons": add_ons})
137
+ except Exception as e:
138
+ print(f"Error fetching add-ons: {str(e)}")
139
+ return jsonify({"success": False, "error": str(e)}), 500
140
+
141
  @cart_blueprint.route("/add_suggestion_to_cart", methods=["POST"])
142
  def add_suggestion_to_cart():
143
  try:
 
144
  data = request.get_json()
145
  item_name = sanitize_input(data.get('item_name').strip())
146
  item_price = data.get('item_price')
 
148
  customer_email = sanitize_input(data.get('customer_email'))
149
  addons = data.get('addons', [])
150
  instructions = sanitize_input(data.get('instructions', ""))
151
+ quantity = data.get('quantity', 1)
152
+
153
+ try:
154
+ quantity = int(quantity)
155
+ if quantity < 1:
156
+ raise ValueError("Quantity must be at least 1")
157
+ item_price = float(item_price)
158
+ except (ValueError, TypeError):
159
+ return jsonify({"success": False, "error": "Invalid quantity or price"}), 400
160
 
 
161
  if not all([item_name, item_price, customer_email]):
162
  return jsonify({"success": False, "error": "Missing required fields"}), 400
163
 
 
164
  addons_price = 0
165
  addons_string = ", ".join(addons) if addons else "None"
166
 
167
  if addons:
 
168
  addons_price = sum(
169
  float(addon.split("($")[1][:-1]) for addon in addons if "($" in addon
170
  )
171
 
 
172
  query = f"""
173
+ SELECT Id, Quantity__c, Add_Ons__c, Add_Ons_Price__c, Instructions__c, Base_Price__c
174
  FROM Cart_Item__c
175
  WHERE Customer_Email__c = '{customer_email}' AND Name = '{item_name}'
176
  """
 
178
  cart_items = result.get("records", [])
179
 
180
  if cart_items:
 
181
  cart_item_id = cart_items[0]['Id']
182
  existing_quantity = cart_items[0]['Quantity__c']
183
  existing_addons = cart_items[0].get('Add_Ons__c', "None")
184
  existing_addons_price = cart_items[0].get('Add_Ons_Price__c', 0)
185
  existing_instructions = cart_items[0].get('Instructions__c', "")
186
+ base_price = cart_items[0].get('Base_Price__c', item_price)
187
 
 
188
  combined_addons = existing_addons if existing_addons != "None" else ""
189
  if addons:
190
  combined_addons = f"{combined_addons}, {addons_string}".strip(", ")
191
 
 
192
  combined_instructions = existing_instructions
193
  if instructions:
194
  combined_instructions = f"{combined_instructions} | {instructions}".strip(" | ")
195
 
196
+ new_quantity = existing_quantity + quantity
197
+ new_addons_price = existing_addons_price + (addons_price * quantity)
198
+ new_total_price = (base_price * new_quantity) + new_addons_price
199
 
 
200
  sf.Cart_Item__c.update(cart_item_id, {
201
+ "Quantity__c": new_quantity,
202
  "Add_Ons__c": combined_addons if combined_addons else "None",
203
+ "Add_Ons_Price__c": new_addons_price,
204
  "Instructions__c": combined_instructions,
205
+ "Price__c": new_total_price
206
  })
207
  else:
208
+ total_price = (item_price * quantity) + (addons_price * quantity)
 
209
  sf.Cart_Item__c.create({
210
  "Name": item_name,
211
  "Price__c": total_price,
212
  "Base_Price__c": item_price,
213
+ "Quantity__c": quantity,
214
+ "Add_Ons_Price__c": addons_price * quantity,
215
  "Add_Ons__c": addons_string,
216
  "Image1__c": item_image,
217
  "Customer_Email__c": customer_email,
 
229
  try:
230
  customer_email = session.get('user_email')
231
  if not customer_email:
232
+ return jsonify({'success': False, 'message': 'User email not found.'}), 400
233
 
234
  sanitized_email = sanitize_input(customer_email)
235
  sanitized_item_name = sanitize_input(item_name)
 
251
 
252
  @cart_blueprint.route("/update_quantity", methods=["POST"])
253
  def update_quantity():
 
254
  data = request.json
255
  email = sanitize_input(data.get('email'))
256
  item_name = sanitize_input(data.get('item_name'))
 
304
 
305
  try:
306
  sanitized_email = sanitize_input(email)
 
 
 
 
 
307
  result = sf.query(f"""
308
  SELECT Id, Name, Price__c, Add_Ons_Price__c, Quantity__c, Add_Ons__c, Instructions__c, Image1__c
309
  FROM Cart_Item__c
 
314
  return jsonify({"success": False, "message": "Cart is empty"}), 400
315
 
316
  subtotal = sum(item['Price__c'] for item in cart_items)
317
+ total = subtotal # No discount for simplicity
318
 
 
 
 
 
 
 
 
319
  bill_items = [
320
  {
321
  "name": item['Name'],
 
327
  } for item in cart_items
328
  ]
329
 
 
330
  menu_query = """
331
  SELECT Name, Price__c, Image1__c, Veg_NonVeg__c, Section__c
332
  FROM Menu_Item__c
 
340
  "cart": {
341
  "items": bill_items,
342
  "subtotal": subtotal,
343
+ "total": total
 
 
344
  },
345
  "menu_items": menu_items
346
  })
 
365
  if not cart:
366
  return jsonify({"success": False, "message": "Cart data is required"}), 400
367
 
 
368
  result = sf.query(f"""
369
  SELECT Id, Name, Price__c, Add_Ons_Price__c, Quantity__c, Add_Ons__c, Instructions__c, Image1__c
370
  FROM Cart_Item__c
 
375
  return jsonify({"success": False, "message": "Cart is empty"}), 400
376
 
377
  subtotal = cart.get("subtotal")
 
378
  total = cart.get("total")
379
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
380
  order_details = "\n".join(
381
  f"{item['Name']} x{item['Quantity__c']} | Add-Ons: {item.get('Add_Ons__c', 'None')} | "
382
  f"Instructions: {item.get('Instructions__c', 'None')} | "
 
384
  for item in cart_items
385
  )
386
 
 
387
  customer_query = sf.query(f"""
388
  SELECT Id FROM Customer_Login__c
389
  WHERE Email__c = '{sanitized_email}'
 
397
  "Customer_Name__c": user_id,
398
  "Customer_Email__c": email,
399
  "Total_Amount__c": subtotal,
 
400
  "Total_Bill__c": total,
401
  "Order_Status__c": "Pending",
402
  "Customer2__c": customer_id,
 
405
  }
406
  order_response = sf.Order__c.create(order_data)
407
 
 
408
  if order_response:
409
  for item in cart_items:
410
  sf.Cart_Item__c.delete(item["Id"])