nagasurendra commited on
Commit
97368a2
·
verified ·
1 Parent(s): b818637

Update cart.py

Browse files
Files changed (1) hide show
  1. cart.py +7 -2
cart.py CHANGED
@@ -188,24 +188,30 @@ def remove_cart_item(item_name):
188
  customer_email = session.get('user_email')
189
  if not customer_email:
190
  return jsonify({'success': False, 'message': 'User email not found. Please log in again.'}), 400
 
191
  query = f"""
192
  SELECT Id FROM Cart_Item__c
193
  WHERE Customer_Email__c = '{customer_email}' AND Name = '{item_name}'
194
  """
195
  result = sf.query(query)
 
196
  if result['totalSize'] == 0:
197
  return jsonify({'success': False, 'message': 'Item not found in cart.'}), 400
 
 
198
  cart_item_id = result['records'][0]['Id']
199
  sf.Cart_Item__c.delete(cart_item_id)
200
  return jsonify({'success': True, 'message': f"'{item_name}' removed successfully!"}), 200
201
  except Exception as e:
202
  print(f"Error: {str(e)}")
203
  return jsonify({'success': False, 'message': f"An error occurred: {str(e)}"}), 500
 
204
  @cart_blueprint.route("/cart/update_quantity", methods=["POST"])
205
  def update_quantity():
206
  data = request.json # Extract JSON data from the request
207
  email = data.get('email')
208
  item_name = data.get('item_name')
 
209
  try:
210
  # Convert quantity to an integer
211
  quantity = int(data.get('quantity'))
@@ -250,13 +256,12 @@ def update_quantity():
250
 
251
  # Return updated item price and subtotal
252
  return jsonify({"success": True, "new_item_price": new_item_price, "subtotal": new_subtotal})
253
- print(f"New item price: {new_item_price}, New subtotal: {new_subtotal}")
254
- return jsonify({"success": True, "new_item_price": new_item_price, "subtotal": new_subtotal})
255
 
256
  except Exception as e:
257
  print(f"Error updating quantity: {str(e)}")
258
  return jsonify({"success": False, "error": str(e)}), 500
259
 
 
260
  @cart_blueprint.route("/checkout", methods=["POST"])
261
  def checkout():
262
  email = session.get('user_email')
 
188
  customer_email = session.get('user_email')
189
  if not customer_email:
190
  return jsonify({'success': False, 'message': 'User email not found. Please log in again.'}), 400
191
+
192
  query = f"""
193
  SELECT Id FROM Cart_Item__c
194
  WHERE Customer_Email__c = '{customer_email}' AND Name = '{item_name}'
195
  """
196
  result = sf.query(query)
197
+
198
  if result['totalSize'] == 0:
199
  return jsonify({'success': False, 'message': 'Item not found in cart.'}), 400
200
+
201
+ # If item exists, delete it
202
  cart_item_id = result['records'][0]['Id']
203
  sf.Cart_Item__c.delete(cart_item_id)
204
  return jsonify({'success': True, 'message': f"'{item_name}' removed successfully!"}), 200
205
  except Exception as e:
206
  print(f"Error: {str(e)}")
207
  return jsonify({'success': False, 'message': f"An error occurred: {str(e)}"}), 500
208
+
209
  @cart_blueprint.route("/cart/update_quantity", methods=["POST"])
210
  def update_quantity():
211
  data = request.json # Extract JSON data from the request
212
  email = data.get('email')
213
  item_name = data.get('item_name')
214
+
215
  try:
216
  # Convert quantity to an integer
217
  quantity = int(data.get('quantity'))
 
256
 
257
  # Return updated item price and subtotal
258
  return jsonify({"success": True, "new_item_price": new_item_price, "subtotal": new_subtotal})
 
 
259
 
260
  except Exception as e:
261
  print(f"Error updating quantity: {str(e)}")
262
  return jsonify({"success": False, "error": str(e)}), 500
263
 
264
+
265
  @cart_blueprint.route("/checkout", methods=["POST"])
266
  def checkout():
267
  email = session.get('user_email')