nagasurendra commited on
Commit
527d54a
·
verified ·
1 Parent(s): b36d1ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -281,16 +281,21 @@ def update_quantity():
281
  f"SELECT Id, Quantity__c FROM Cart_Item__c WHERE Customer_Email__c = '{email}' AND Name = '{item_name}'"
282
  )['records']
283
 
284
- if not cart_items:
285
- return jsonify({"success": False, "error": "Cart item not found."}), 404
 
 
 
 
286
 
287
- # Get the first matching record ID (assuming the item name is unique per user)
288
- cart_item_id = cart_items[0]['Id']
 
 
 
289
 
290
- # Update the quantity in Salesforce
291
- sf.Cart_Item__c.update(cart_item_id, {"Quantity__c": quantity})
292
 
293
- return jsonify({"success": True, "new_quantity": quantity})
294
  except Exception as e:
295
  return jsonify({"success": False, "error": str(e)}), 500
296
 
 
281
  f"SELECT Id, Quantity__c FROM Cart_Item__c WHERE Customer_Email__c = '{email}' AND Name = '{item_name}'"
282
  )['records']
283
 
284
+ if cart_items:
285
+ cart_item_id = cart_items[0]['Id']
286
+ base_price = cart_items[0]['Base_Price__c']
287
+ addons_price = sum([float(price) for price in cart_items[0].get('Add_Ons__c', "0").split("$")[1::2]]) # Example parsing logic
288
+
289
+ new_price = (base_price + addons_price) * quantity
290
 
291
+ # Update Salesforce record
292
+ sf.Cart_Item__c.update(cart_item_id, {
293
+ "Quantity__c": quantity,
294
+ "Price__c": new_price
295
+ })
296
 
297
+ return jsonify({"success": True, "new_quantity": quantity, "new_price": new_price})
 
298
 
 
299
  except Exception as e:
300
  return jsonify({"success": False, "error": str(e)}), 500
301