Spaces:
Sleeping
Sleeping
Update menu.py
Browse files
menu.py
CHANGED
@@ -128,4 +128,53 @@ def menu():
|
|
128 |
user_name=user_name, # Pass name to the template
|
129 |
first_letter=first_letter # Pass first letter to the template
|
130 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
|
|
|
128 |
user_name=user_name, # Pass name to the template
|
129 |
first_letter=first_letter # Pass first letter to the template
|
130 |
)
|
131 |
+
@app.route('/api/addons', methods=['GET'])
|
132 |
+
def get_addons():
|
133 |
+
item_name = request.args.get('item_name')
|
134 |
+
item_section = request.args.get('item_section')
|
135 |
+
|
136 |
+
# Check if both item_name and item_section are provided
|
137 |
+
if not item_name or not item_section:
|
138 |
+
return jsonify({"success": False, "error": "Item name and section are required."}), 400
|
139 |
+
|
140 |
+
try:
|
141 |
+
# Fetch customization options from Salesforce based on the section
|
142 |
+
query = f"""
|
143 |
+
SELECT Name, Customization_Type__c, Options__c, Max_Selections__c, Extra_Charge__c, Extra_Charge_Amount__c
|
144 |
+
FROM Customization_Options__c
|
145 |
+
WHERE Section__c = '{item_section}'
|
146 |
+
"""
|
147 |
+
result = sf.query(query)
|
148 |
+
addons = result.get('records', [])
|
149 |
+
|
150 |
+
# Check if we found any addons
|
151 |
+
if not addons:
|
152 |
+
return jsonify({"success": False, "error": "No customization options found for the given section."}), 404
|
153 |
+
|
154 |
+
# Format data for frontend
|
155 |
+
formatted_addons = []
|
156 |
+
for addon in addons:
|
157 |
+
# Ensure 'Options__c' exists and is not None
|
158 |
+
options = addon.get("Options__c", "")
|
159 |
+
if options: # If options are available, split them
|
160 |
+
options = options.split(", ") # Convert comma-separated options into a list
|
161 |
+
else:
|
162 |
+
options = [] # If no options, default to an empty list
|
163 |
+
|
164 |
+
formatted_addons.append({
|
165 |
+
"name": addon["Name"],
|
166 |
+
"type": addon["Customization_Type__c"],
|
167 |
+
"options": options,
|
168 |
+
"max_selections": addon.get("Max_Selections__c", 1),
|
169 |
+
"extra_charge": addon.get("Extra_Charge__c", False),
|
170 |
+
"extra_charge_amount": addon.get("Extra_Charge_Amount__c", 0)
|
171 |
+
})
|
172 |
+
|
173 |
+
return jsonify({"success": True, "addons": formatted_addons})
|
174 |
+
|
175 |
+
except Exception as e:
|
176 |
+
# Log the exception for debugging
|
177 |
+
app.logger.error(f"Error fetching addons: {str(e)}")
|
178 |
+
return jsonify({"success": False, "error": "An error occurred while fetching customization options."}), 500
|
179 |
+
|
180 |
|