Spaces:
Running
Running
Update app.py
Browse files
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
|
285 |
-
|
|
|
|
|
|
|
|
|
286 |
|
287 |
-
|
288 |
-
|
|
|
|
|
|
|
289 |
|
290 |
-
|
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 |
|