nagasurendra commited on
Commit
acd347f
·
verified ·
1 Parent(s): 90e7132

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -321,23 +321,30 @@ def update_quantity():
321
  base_price = cart_items[0]['Base_Price__c']
322
  addons_price = cart_items[0].get('Add_Ons_Price__c', 0)
323
 
324
- # Calculate the new price
325
- new_price = base_price * quantity
326
 
327
  # Update the record in Salesforce
328
  sf.Cart_Item__c.update(cart_item_id, {
329
  "Quantity__c": quantity,
330
- "Price__c": new_price, # Update base price
331
- "Add_Ons_Price__c": addons_price # Add-ons price remains constant
332
  })
333
 
334
- return jsonify({"success": True, "new_quantity": quantity, "new_price": new_price})
 
 
 
 
 
 
 
 
 
335
  except Exception as e:
336
  print(f"Error updating quantity: {str(e)}")
337
  return jsonify({"success": False, "error": str(e)}), 500
338
 
339
 
340
-
341
  @app.route("/checkout", methods=["POST"])
342
  def checkout():
343
  email = session.get('user_email')
 
321
  base_price = cart_items[0]['Base_Price__c']
322
  addons_price = cart_items[0].get('Add_Ons_Price__c', 0)
323
 
324
+ # Calculate the new item price
325
+ new_item_price = (base_price * quantity) + addons_price
326
 
327
  # Update the record in Salesforce
328
  sf.Cart_Item__c.update(cart_item_id, {
329
  "Quantity__c": quantity,
330
+ "Price__c": new_item_price, # Update base price
 
331
  })
332
 
333
+ # Recalculate the subtotal for all items in the cart
334
+ cart_items = sf.query(f"""
335
+ SELECT Price__c, Add_Ons_Price__c
336
+ FROM Cart_Item__c
337
+ WHERE Customer_Email__c = '{email}'
338
+ """)['records']
339
+ new_subtotal = sum(item['Price__c'] for item in cart_items) + sum(item['Add_Ons_Price__c'] for item in cart_items)
340
+
341
+ # Return updated item price and subtotal
342
+ return jsonify({"success": True, "new_item_price": new_item_price, "subtotal": new_subtotal})
343
  except Exception as e:
344
  print(f"Error updating quantity: {str(e)}")
345
  return jsonify({"success": False, "error": str(e)}), 500
346
 
347
 
 
348
  @app.route("/checkout", methods=["POST"])
349
  def checkout():
350
  email = session.get('user_email')