Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -894,23 +894,43 @@ def remove_cart_item(item_name):
|
|
| 894 |
print(f"Error: {str(e)}")
|
| 895 |
return jsonify({'success': False, 'message': f"An error occurred: {str(e)}"}), 500
|
| 896 |
|
| 897 |
-
|
| 898 |
@app.route('/api/addons', methods=['GET'])
|
| 899 |
def get_addons():
|
| 900 |
-
item_name = request.args.get('item_name')
|
| 901 |
-
|
| 902 |
-
|
|
|
|
|
|
|
|
|
|
| 903 |
try:
|
| 904 |
-
# Fetch
|
| 905 |
query = f"""
|
| 906 |
-
SELECT Name,
|
| 907 |
-
FROM
|
|
|
|
| 908 |
"""
|
| 909 |
-
|
| 910 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 911 |
except Exception as e:
|
| 912 |
print(f"Error fetching add-ons: {e}")
|
| 913 |
return jsonify({"success": False, "error": "Unable to fetch add-ons. Please try again later."})
|
|
|
|
| 914 |
@app.route("/cart/update_quantity", methods=["POST"])
|
| 915 |
def update_quantity():
|
| 916 |
data = request.json # Extract JSON data from the request
|
|
|
|
| 894 |
print(f"Error: {str(e)}")
|
| 895 |
return jsonify({'success': False, 'message': f"An error occurred: {str(e)}"}), 500
|
| 896 |
|
|
|
|
| 897 |
@app.route('/api/addons', methods=['GET'])
|
| 898 |
def get_addons():
|
| 899 |
+
item_name = request.args.get('item_name')
|
| 900 |
+
item_section = request.args.get('item_section')
|
| 901 |
+
|
| 902 |
+
if not item_name or not item_section:
|
| 903 |
+
return jsonify({"success": False, "error": "Item name and section are required."})
|
| 904 |
+
|
| 905 |
try:
|
| 906 |
+
# Fetch customization options from Salesforce based on the section
|
| 907 |
query = f"""
|
| 908 |
+
SELECT Name, Customization_Type__c, Options__c, Max_Selections__c, Extra_Charge__c, Extra_Charge_Amount__c
|
| 909 |
+
FROM Customization_Options__c
|
| 910 |
+
WHERE Section__c = '{item_section}'
|
| 911 |
"""
|
| 912 |
+
result = sf.query(query)
|
| 913 |
+
addons = result.get('records', [])
|
| 914 |
+
|
| 915 |
+
# Format data for frontend
|
| 916 |
+
formatted_addons = []
|
| 917 |
+
for addon in addons:
|
| 918 |
+
options = addon.get("Options__c", "").split(", ") # Convert comma-separated options into a list
|
| 919 |
+
formatted_addons.append({
|
| 920 |
+
"name": addon["Name"],
|
| 921 |
+
"type": addon["Customization_Type__c"],
|
| 922 |
+
"options": options,
|
| 923 |
+
"max_selections": addon.get("Max_Selections__c", 1),
|
| 924 |
+
"extra_charge": addon.get("Extra_Charge__c", False),
|
| 925 |
+
"extra_charge_amount": addon.get("Extra_Charge_Amount__c", 0)
|
| 926 |
+
})
|
| 927 |
+
|
| 928 |
+
return jsonify({"success": True, "addons": formatted_addons})
|
| 929 |
+
|
| 930 |
except Exception as e:
|
| 931 |
print(f"Error fetching add-ons: {e}")
|
| 932 |
return jsonify({"success": False, "error": "Unable to fetch add-ons. Please try again later."})
|
| 933 |
+
|
| 934 |
@app.route("/cart/update_quantity", methods=["POST"])
|
| 935 |
def update_quantity():
|
| 936 |
data = request.json # Extract JSON data from the request
|