Spaces:
Sleeping
Sleeping
Update menu.py
Browse files
menu.py
CHANGED
|
@@ -1,374 +1,149 @@
|
|
| 1 |
from flask import Blueprint, render_template, request, session, jsonify, redirect, url_for
|
| 2 |
-
import os
|
| 3 |
-
import re
|
| 4 |
from salesforce import get_salesforce_connection
|
| 5 |
|
| 6 |
-
menu_blueprint = Blueprint('menu', __name__)
|
| 7 |
-
|
| 8 |
-
# Initialize Salesforce connection
|
| 9 |
sf = get_salesforce_connection()
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
elif video_url.startswith('/'):
|
| 29 |
-
return video_url
|
| 30 |
-
elif video_url.startswith('069'):
|
| 31 |
-
return f"https://biryanihub-dev-ed.develop.my.salesforce.com/sfc/servlet.shepherd/version/download/{video_url}"
|
| 32 |
-
if not os.path.exists(PLACEHOLDER_PATH):
|
| 33 |
-
with open(PLACEHOLDER_PATH, 'wb') as f:
|
| 34 |
-
f.close()
|
| 35 |
-
print(f"Created missing placeholder video at {PLACEHOLDER_PATH}")
|
| 36 |
-
return f"/static/{PLACEHOLDER_VIDEO}"
|
| 37 |
|
| 38 |
-
def fetch_menu_data(selected_category, user_email):
|
| 39 |
-
"""Common function to fetch and process menu data."""
|
| 40 |
try:
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
user_result = sf.query(user_query)
|
| 44 |
-
if not user_result.get('records'):
|
| 45 |
-
return None, None, None, None, None, None
|
| 46 |
-
|
| 47 |
-
referral_code = user_result['records'][0].get('Referral__c', 'N/A')
|
| 48 |
-
reward_points = user_result['records'][0].get('Reward_Points__c', 0)
|
| 49 |
-
|
| 50 |
-
# Get cart item count
|
| 51 |
-
cart_query = f"SELECT COUNT() FROM Cart_Item__c WHERE Customer_Email__c = '{user_email}'"
|
| 52 |
-
cart_count_result = sf.query(cart_query)
|
| 53 |
-
cart_item_count = cart_count_result.get('totalSize', 0)
|
| 54 |
-
|
| 55 |
-
# Fetch all Menu_Item__c records
|
| 56 |
-
menu_query = """
|
| 57 |
-
SELECT Name, Price__c, Description__c, Image1__c, Image2__c,
|
| 58 |
-
Veg_NonVeg__c, Section__c, Total_Ordered__c, Video1__c,
|
| 59 |
-
IngredientsInfo__c, NutritionalInfo__c, Allergens__c
|
| 60 |
-
FROM Menu_Item__c
|
| 61 |
-
"""
|
| 62 |
-
menu_result = sf.query_all(menu_query)
|
| 63 |
-
food_items = menu_result.get('records', [])
|
| 64 |
-
|
| 65 |
-
# Process menu items
|
| 66 |
-
for item in food_items:
|
| 67 |
-
item['Total_Ordered__c'] = item.get('Total_Ordered__c', 0) or 0
|
| 68 |
-
item['Video1__c'] = get_valid_video_path(item['Name'], item.get('Video1__c'))
|
| 69 |
-
item['Section__c'] = item.get('Section__c', "Others")
|
| 70 |
-
item['Description__c'] = item.get('Description__c', "No description available")
|
| 71 |
-
item['IngredientsInfo__c'] = item.get('IngredientsInfo__c', "Not specified")
|
| 72 |
-
item['NutritionalInfo__c'] = item.get('NutritionalInfo__c', "Not available")
|
| 73 |
-
item['Allergens__c'] = item.get('Allergens__c', "None listed")
|
| 74 |
-
item['is_menu_item'] = True
|
| 75 |
-
|
| 76 |
-
# Fetch all Custom_Dish__c records (no restrictions to ensure all custom dishes are shown)
|
| 77 |
-
custom_dish_query = """
|
| 78 |
-
SELECT Name, Price__c, Description__c, Image1__c, Image2__c,
|
| 79 |
-
Veg_NonVeg__c, Section__c, Total_Ordered__c
|
| 80 |
-
FROM Custom_Dish__c
|
| 81 |
-
"""
|
| 82 |
-
custom_dish_result = sf.query_all(custom_dish_query)
|
| 83 |
-
custom_dishes = custom_dish_result.get('records', [])
|
| 84 |
|
| 85 |
-
#
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
item['Section__c'] = item.get('Section__c', "Customized dish")
|
| 90 |
-
item['Description__c'] = item.get('Description__c', "No description available")
|
| 91 |
-
item['IngredientsInfo__c'] = "Customized ingredients"
|
| 92 |
-
item['NutritionalInfo__c'] = "Not available"
|
| 93 |
-
item['Allergens__c'] = "Customized, check description"
|
| 94 |
-
item['is_menu_item'] = False
|
| 95 |
-
|
| 96 |
-
# Merge all items
|
| 97 |
-
all_items = food_items + custom_dishes
|
| 98 |
-
ordered_menu = {section: [] for section in SECTION_ORDER}
|
| 99 |
-
|
| 100 |
-
# Process best sellers
|
| 101 |
-
best_sellers = sorted(all_items, key=lambda x: x['Total_Ordered__c'], reverse=True)
|
| 102 |
-
if selected_category == "Veg":
|
| 103 |
-
best_sellers = [item for item in best_sellers if item.get("Veg_NonVeg__c") in ["Veg", "both"]]
|
| 104 |
-
elif selected_category == "Non veg":
|
| 105 |
-
best_sellers = [item for item in best_sellers if item.get("Veg_NonVeg__c") in ["Non veg", "both"]]
|
| 106 |
-
elif selected_category == "Customized Dish":
|
| 107 |
-
best_sellers = [item for item in best_sellers if item.get("Section__c") == "Customized dish"]
|
| 108 |
-
ordered_menu["Best Sellers"] = best_sellers[:4]
|
| 109 |
-
|
| 110 |
-
# Organize items into sections
|
| 111 |
-
added_item_names = set()
|
| 112 |
-
for item in all_items:
|
| 113 |
-
section = item['Section__c']
|
| 114 |
if section not in ordered_menu:
|
| 115 |
ordered_menu[section] = []
|
| 116 |
-
|
| 117 |
-
if item['Name'] in added_item_names:
|
| 118 |
-
continue
|
| 119 |
-
|
| 120 |
-
veg_nonveg = item.get("Veg_NonVeg__c", "both")
|
| 121 |
-
if selected_category == "Veg" and veg_nonveg not in ["Veg", "both"]:
|
| 122 |
-
continue
|
| 123 |
-
if selected_category == "Non veg" and veg_nonveg not in ["Non veg", "both"]:
|
| 124 |
-
continue
|
| 125 |
-
if selected_category == "Customized Dish" and section != "Customized dish":
|
| 126 |
-
continue
|
| 127 |
-
|
| 128 |
ordered_menu[section].append(item)
|
| 129 |
-
added_item_names.add(item['Name'])
|
| 130 |
|
| 131 |
-
#
|
| 132 |
-
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
# Frequency analysis for add-ons and instructions
|
| 143 |
-
addon_counts = {}
|
| 144 |
-
instruction_counts = {}
|
| 145 |
-
for order in past_orders:
|
| 146 |
-
order_details = order.get('Order_Details__c', '').split('\n')
|
| 147 |
-
for line in order_details:
|
| 148 |
-
item_parts = line.split('|')
|
| 149 |
-
if len(item_parts) >= 5:
|
| 150 |
-
addons = item_parts[1].strip().replace('Add-Ons:', '').split(', ')
|
| 151 |
-
instructions = item_parts[2].strip().replace('Instructions:', '').split(', ')
|
| 152 |
-
cleaned_addons = [re.sub(r"\s?\(\$\d+(\.\d{2})?\)", "", addon).strip() for addon in addons]
|
| 153 |
-
for addon in cleaned_addons:
|
| 154 |
-
individual_addons = addon.split(';')
|
| 155 |
-
for individual_addon in individual_addons:
|
| 156 |
-
individual_addon = individual_addon.strip()
|
| 157 |
-
if individual_addon:
|
| 158 |
-
addon_counts[individual_addon] = addon_counts.get(individual_addon, 0) + 1
|
| 159 |
-
for instruction in instructions:
|
| 160 |
-
instruction = instruction.strip()
|
| 161 |
-
if instruction:
|
| 162 |
-
instruction_counts[instruction] = instruction_counts.get(instruction, 0) + 1
|
| 163 |
-
|
| 164 |
-
most_common_addons = sorted(addon_counts, key=addon_counts.get, reverse=True)[:3]
|
| 165 |
-
most_common_instructions = sorted(instruction_counts, key=instruction_counts.get, reverse=True)[:3]
|
| 166 |
-
|
| 167 |
-
return ordered_menu, referral_code, reward_points, cart_item_count, most_common_addons, most_common_instructions
|
| 168 |
|
| 169 |
except Exception as e:
|
| 170 |
-
print(f"Error fetching menu
|
| 171 |
-
return
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
user_email = session.get('user_email')
|
| 184 |
-
if not user_email:
|
| 185 |
-
user_email = request.args.get("email")
|
| 186 |
-
user_name = request.args.get("name")
|
| 187 |
-
if user_email and user_name:
|
| 188 |
-
session['user_email'] = user_email
|
| 189 |
-
session['user_name'] = user_name
|
| 190 |
-
else:
|
| 191 |
-
return redirect(url_for("login"))
|
| 192 |
-
else:
|
| 193 |
-
user_name = session.get('user_name')
|
| 194 |
-
|
| 195 |
-
first_letter = user_name[0].upper() if user_name else "A"
|
| 196 |
-
ordered_menu, referral_code, reward_points, cart_item_count, most_common_addons, most_common_instructions = fetch_menu_data(selected_category, user_email)
|
| 197 |
-
if ordered_menu is None:
|
| 198 |
-
return redirect(url_for('login'))
|
| 199 |
-
|
| 200 |
-
categories = ["All", "Veg", "Non veg", "Customized Dish"]
|
| 201 |
-
|
| 202 |
-
return render_template(
|
| 203 |
-
"menu.html",
|
| 204 |
-
ordered_menu=ordered_menu,
|
| 205 |
-
categories=categories,
|
| 206 |
-
selected_category=selected_category,
|
| 207 |
-
referral_code=referral_code,
|
| 208 |
-
reward_points=reward_points,
|
| 209 |
-
user_name=user_name,
|
| 210 |
-
first_letter=first_letter,
|
| 211 |
-
cart_item_count=cart_item_count,
|
| 212 |
-
most_common_addons=[addon.strip() for addon in most_common_addons],
|
| 213 |
-
most_common_instructions=most_common_instructions
|
| 214 |
-
)
|
| 215 |
-
|
| 216 |
-
@menu_blueprint.route("/search", methods=["GET"])
|
| 217 |
-
def search():
|
| 218 |
-
selected_category = request.args.get("category", "All")
|
| 219 |
-
user_email = session.get('user_email')
|
| 220 |
-
if not user_email:
|
| 221 |
-
return redirect(url_for("login"))
|
| 222 |
-
user_name = session.get('user_name')
|
| 223 |
-
first_letter = user_name[0].upper() if user_name else "A"
|
| 224 |
-
|
| 225 |
-
ordered_menu, referral_code, reward_points, cart_item_count, most_common_addons, most_common_instructions = fetch_menu_data(selected_category, user_email)
|
| 226 |
-
if ordered_menu is None:
|
| 227 |
-
return redirect(url_for('login'))
|
| 228 |
-
|
| 229 |
-
return render_template(
|
| 230 |
-
"search.html",
|
| 231 |
-
ordered_menu=ordered_menu,
|
| 232 |
-
user_name=user_name,
|
| 233 |
-
first_letter=first_letter,
|
| 234 |
-
cart_item_count=cart_item_count,
|
| 235 |
-
most_common_addons=[addon.strip() for addon in most_common_addons],
|
| 236 |
-
most_common_instructions=most_common_instructions
|
| 237 |
-
)
|
| 238 |
-
|
| 239 |
-
@menu_blueprint.route('/api/addons', methods=['GET'])
|
| 240 |
-
def get_addons():
|
| 241 |
-
item_name = request.args.get('item_name')
|
| 242 |
-
item_section = request.args.get('item_section')
|
| 243 |
-
if not item_name or not item_section:
|
| 244 |
-
return jsonify({"success": False, "error": "Item name and section are required."}), 400
|
| 245 |
-
|
| 246 |
try:
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
WHERE Section__c = '{item_section}'
|
| 251 |
-
"""
|
| 252 |
-
result = sf.query_all(query)
|
| 253 |
-
addons = result.get('records', [])
|
| 254 |
-
|
| 255 |
-
if not addons:
|
| 256 |
-
return jsonify({"success": False, "error": "No customization options found for the given section."}), 404
|
| 257 |
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
except Exception as e:
|
| 274 |
-
print(f"Error
|
| 275 |
-
return jsonify({"success": False, "error":
|
| 276 |
|
| 277 |
-
@menu_blueprint.route(
|
| 278 |
-
def
|
| 279 |
try:
|
| 280 |
-
data = request.
|
| 281 |
-
|
| 282 |
-
item_price = float(data.get('itemPrice', 0))
|
| 283 |
-
item_image = data.get('itemImage', '')
|
| 284 |
-
addons = data.get('addons', [])
|
| 285 |
-
instructions = data.get('instructions', '')
|
| 286 |
-
category = data.get('category', '')
|
| 287 |
-
section = data.get('section', '')
|
| 288 |
-
quantity = int(data.get('quantity', 1))
|
| 289 |
-
customer_email = session.get('user_email')
|
| 290 |
|
| 291 |
-
|
| 292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
result = sf.query_all(query)
|
| 300 |
-
cart_items = result.get("records", [])
|
| 301 |
|
| 302 |
-
|
| 303 |
-
new_addons = "; ".join([f"{addon['name']} (${addon['price']})" for addon in addons]) if addons else "None"
|
| 304 |
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
existing_quantity = int(cart_item.get('Quantity__c', 0))
|
| 309 |
-
existing_addons = cart_item.get('Add_Ons__c', "None")
|
| 310 |
-
existing_addons_price = float(cart_item.get('Add_Ons_Price__c', 0))
|
| 311 |
-
existing_instructions = cart_item.get('Instructions__c', "")
|
| 312 |
-
|
| 313 |
-
combined_addons = existing_addons if existing_addons != "None" else ""
|
| 314 |
-
if new_addons != "None":
|
| 315 |
-
combined_addons = f"{combined_addons}; {new_addons}".strip("; ")
|
| 316 |
-
|
| 317 |
-
combined_instructions = existing_instructions
|
| 318 |
-
if instructions:
|
| 319 |
-
combined_instructions = f"{existing_instructions} | {instructions}".strip(" | ")
|
| 320 |
-
|
| 321 |
-
combined_addons_list = combined_addons.split("; ")
|
| 322 |
-
combined_addons_price = sum(
|
| 323 |
-
float(addon.split("($")[1][:-1]) for addon in combined_addons_list if "($" in addon
|
| 324 |
-
)
|
| 325 |
|
| 326 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
"Price__c": total_price,
|
| 334 |
-
"Category__c": category,
|
| 335 |
-
"Section__c": section
|
| 336 |
-
})
|
| 337 |
-
else:
|
| 338 |
-
total_price = item_price * quantity + addons_price
|
| 339 |
-
sf.Cart_Item__c.create({
|
| 340 |
-
"Name": item_name,
|
| 341 |
-
"Price__c": total_price,
|
| 342 |
-
"Base_Price__c": item_price,
|
| 343 |
-
"Quantity__c": quantity,
|
| 344 |
-
"Add_Ons_Price__c": addons_price,
|
| 345 |
-
"Add_Ons__c": new_addons,
|
| 346 |
-
"Image1__c": item_image,
|
| 347 |
-
"Customer_Email__c": customer_email,
|
| 348 |
-
"Instructions__c": instructions,
|
| 349 |
-
"Category__c": category,
|
| 350 |
-
"Section__c": section
|
| 351 |
-
})
|
| 352 |
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
"itemName": item["Name"],
|
| 358 |
-
"quantity": item["Quantity__c"],
|
| 359 |
-
"price": item["Price__c"],
|
| 360 |
-
"image": item["Image1__c"],
|
| 361 |
-
"addons": item["Add_Ons__c"],
|
| 362 |
-
"instructions": item["Instructions__c"],
|
| 363 |
-
"category": item["Category__c"],
|
| 364 |
-
"section": item["Section__c"]
|
| 365 |
-
} for item in cart_result.get("records", [])]
|
| 366 |
|
| 367 |
-
return jsonify({"success": True, "
|
| 368 |
|
| 369 |
-
except ValueError as e:
|
| 370 |
-
print(f"Invalid data format in cart add: {str(e)}")
|
| 371 |
-
return jsonify({"success": False, "error": f"Invalid data format: {str(e)}"}), 400
|
| 372 |
except Exception as e:
|
| 373 |
-
print(f"Error
|
| 374 |
-
return jsonify({"success": False, "error":
|
|
|
|
| 1 |
from flask import Blueprint, render_template, request, session, jsonify, redirect, url_for
|
|
|
|
|
|
|
| 2 |
from salesforce import get_salesforce_connection
|
| 3 |
|
|
|
|
|
|
|
|
|
|
| 4 |
sf = get_salesforce_connection()
|
| 5 |
+
menu_blueprint = Blueprint('menu', __name__)
|
| 6 |
|
| 7 |
+
@menu_blueprint.route("/menu", methods=["GET"])
|
| 8 |
+
def menu():
|
| 9 |
+
email = session.get('user_email')
|
| 10 |
+
user_name = session.get('user_name')
|
| 11 |
+
if not email or not user_name:
|
| 12 |
+
return redirect(url_for("login"))
|
| 13 |
|
| 14 |
+
category = request.args.get('category', 'All')
|
| 15 |
+
veg_filter = request.args.get('veg', None)
|
| 16 |
+
|
| 17 |
+
# Build query based on filters
|
| 18 |
+
query_conditions = []
|
| 19 |
+
if veg_filter:
|
| 20 |
+
category = 'Veg'
|
| 21 |
+
query_conditions.append("Veg_NonVeg__c = 'Veg'")
|
| 22 |
+
elif category == 'All':
|
| 23 |
+
query_conditions.append("(Veg_NonVeg__c = 'Veg' OR Veg_NonVeg__c = 'Non veg')")
|
| 24 |
+
elif category == 'Customized Dish':
|
| 25 |
+
query_conditions.append(f"Section__c = 'Customized Dish' AND Customer_Email__c = '{email}'")
|
| 26 |
+
else:
|
| 27 |
+
query_conditions.append(f"Veg_NonVeg__c = '{category}'")
|
| 28 |
|
| 29 |
+
query = f"""
|
| 30 |
+
SELECT Name, Price__c, Image1__c, Image2__c, Video1__c, Section__c, Description__c, Ingredientsinfo__c, NutritionalInfo__c, Allergens__c, Veg_NonVeg__c
|
| 31 |
+
FROM Menu_Item__c
|
| 32 |
+
WHERE {' AND '.join(query_conditions)}
|
| 33 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
|
|
|
|
|
|
| 35 |
try:
|
| 36 |
+
result = sf.query(query)
|
| 37 |
+
menu_items = result.get("records", [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
# Organize menu items by section
|
| 40 |
+
ordered_menu = {}
|
| 41 |
+
for item in menu_items:
|
| 42 |
+
section = item.get('Section__c', 'Other')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
if section not in ordered_menu:
|
| 44 |
ordered_menu[section] = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
ordered_menu[section].append(item)
|
|
|
|
| 46 |
|
| 47 |
+
# Fetch most common add-ons (simplified for this example)
|
| 48 |
+
most_common_addons = ["Medium", "Raita"]
|
| 49 |
|
| 50 |
+
return render_template(
|
| 51 |
+
"menu.html",
|
| 52 |
+
ordered_menu=ordered_menu,
|
| 53 |
+
selected_category=category,
|
| 54 |
+
user_name=user_name,
|
| 55 |
+
first_letter=user_name[0].upper(),
|
| 56 |
+
most_common_addons=most_common_addons
|
| 57 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
except Exception as e:
|
| 60 |
+
print(f"Error fetching menu items: {e}")
|
| 61 |
+
return render_template(
|
| 62 |
+
"menu.html",
|
| 63 |
+
ordered_menu={},
|
| 64 |
+
selected_category=category,
|
| 65 |
+
user_name=user_name,
|
| 66 |
+
first_letter=user_name[0].upper(),
|
| 67 |
+
most_common_addons=[]
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
@menu_blueprint.route("/menu/save_custom_dish", methods=["POST"])
|
| 71 |
+
def save_custom_dish():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
try:
|
| 73 |
+
email = session.get('user_email')
|
| 74 |
+
if not email:
|
| 75 |
+
return jsonify({"success": False, "error": "User not logged in."}), 401
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
data = request.get_json()
|
| 78 |
+
menu_item = data.get('menu_item')
|
| 79 |
+
ingredients = data.get('ingredients', [])
|
| 80 |
+
instructions = data.get('instructions', '')
|
| 81 |
+
item_price = float(data.get('itemPrice', 10.00))
|
| 82 |
+
item_image = data.get('itemImage', 'https://via.placeholder.com/120')
|
| 83 |
+
|
| 84 |
+
# Create a new Menu_Item__c record for the custom dish
|
| 85 |
+
sf.Menu_Item__c.create({
|
| 86 |
+
"Name": menu_item['name'],
|
| 87 |
+
"Price__c": item_price,
|
| 88 |
+
"Image1__c": item_image,
|
| 89 |
+
"Section__c": "Customized Dish",
|
| 90 |
+
"Description__c": instructions,
|
| 91 |
+
"Ingredientsinfo__c": ", ".join(i['name'] for i in ingredients),
|
| 92 |
+
"Customer_Email__c": email,
|
| 93 |
+
"Veg_NonVeg__c": "Custom"
|
| 94 |
+
})
|
| 95 |
+
|
| 96 |
+
return jsonify({"success": True, "message": "Custom dish saved successfully"})
|
| 97 |
|
| 98 |
except Exception as e:
|
| 99 |
+
print(f"Error saving custom dish: {e}")
|
| 100 |
+
return jsonify({"success": False, "error": str(e)}), 500
|
| 101 |
|
| 102 |
+
@menu_blueprint.route("/get_ingredients", methods=["POST"])
|
| 103 |
+
def get_ingredients():
|
| 104 |
try:
|
| 105 |
+
data = request.get_json()
|
| 106 |
+
dietary_preference = data.get('dietary_preference', 'all')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
+
# Simplified ingredient fetching logic
|
| 109 |
+
ingredients = [
|
| 110 |
+
{"name": "Tomato", "image_url": "https://via.placeholder.com/120", "category": "vegetarian"},
|
| 111 |
+
{"name": "Chicken", "image_url": "https://via.placeholder.com/120", "category": "non-vegetarian"},
|
| 112 |
+
{"name": "Onion", "image_url": "https://via.placeholder.com/120", "category": "vegetarian"},
|
| 113 |
+
{"name": "Beef", "image_url": "https://via.placeholder.com/120", "category": "non-vegetarian"}
|
| 114 |
+
]
|
| 115 |
|
| 116 |
+
filtered_ingredients = [
|
| 117 |
+
ingredient for ingredient in ingredients
|
| 118 |
+
if dietary_preference == 'all' or ingredient['category'] == dietary_preference.lower()
|
| 119 |
+
or dietary_preference in ingredient['name'].lower()
|
| 120 |
+
]
|
|
|
|
|
|
|
| 121 |
|
| 122 |
+
return jsonify({"success": True, "ingredients": filtered_ingredients})
|
|
|
|
| 123 |
|
| 124 |
+
except Exception as e:
|
| 125 |
+
print(f"Error fetching ingredients: {e}")
|
| 126 |
+
return jsonify({"success": False, "error": str(e)}), 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
+
@menu_blueprint.route("/get_menu_items", methods=["POST"])
|
| 129 |
+
def get_menu_items():
|
| 130 |
+
try:
|
| 131 |
+
data = request.get_json()
|
| 132 |
+
ingredient_names = data.get('ingredient_names', '')
|
| 133 |
|
| 134 |
+
# Simplified menu item fetching logic
|
| 135 |
+
menu_items = [
|
| 136 |
+
{"name": "Tomato Curry", "image_url": "https://via.placeholder.com/120"},
|
| 137 |
+
{"name": "Chicken Biryani", "image_url": "https://via.placeholder.com/120"}
|
| 138 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
+
filtered_items = [
|
| 141 |
+
item for item in menu_items
|
| 142 |
+
if not ingredient_names or any(ing in item['name'].lower() for ing in ingredient_names.split())
|
| 143 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
+
return jsonify({"success": True, "menu_items": filtered_items})
|
| 146 |
|
|
|
|
|
|
|
|
|
|
| 147 |
except Exception as e:
|
| 148 |
+
print(f"Error fetching menu items: {e}")
|
| 149 |
+
return jsonify({"success": False, "error": str(e)}), 500
|