Spaces:
Sleeping
Sleeping
Update menu.py
Browse files
menu.py
CHANGED
@@ -52,7 +52,7 @@ def fetch_menu_data(selected_category, 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,
|
@@ -71,14 +71,13 @@ def fetch_menu_data(selected_category, user_email):
|
|
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
|
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 |
-
WHERE CreatedDate >= LAST_N_DAYS:7 AND Total_Ordered__c > 10
|
82 |
"""
|
83 |
custom_dish_result = sf.query_all(custom_dish_query)
|
84 |
custom_dishes = custom_dish_result.get('records', [])
|
@@ -89,7 +88,10 @@ def fetch_menu_data(selected_category, user_email):
|
|
89 |
item['Video1__c'] = get_valid_video_path(item['Name'])
|
90 |
item['Section__c'] = item.get('Section__c', "Customized dish")
|
91 |
item['Description__c'] = item.get('Description__c', "No description available")
|
92 |
-
item['
|
|
|
|
|
|
|
93 |
|
94 |
# Merge all items
|
95 |
all_items = food_items + custom_dishes
|
@@ -159,11 +161,8 @@ def fetch_menu_data(selected_category, user_email):
|
|
159 |
if instruction:
|
160 |
instruction_counts[instruction] = instruction_counts.get(instruction, 0) + 1
|
161 |
|
162 |
-
|
163 |
-
most_common_addons = sorted(addon_counts, key=addon_counts.get, reverse=True)
|
164 |
most_common_instructions = sorted(instruction_counts, key=instruction_counts.get, reverse=True)[:3]
|
165 |
-
print(f"Most common add-ons: {most_common_addons}")
|
166 |
-
print(f"Most common instructions: {most_common_instructions}")
|
167 |
|
168 |
return ordered_menu, referral_code, reward_points, cart_item_count, most_common_addons, most_common_instructions
|
169 |
|
@@ -173,19 +172,15 @@ def fetch_menu_data(selected_category, user_email):
|
|
173 |
|
174 |
@menu_blueprint.route("/menu", methods=["GET", "POST"])
|
175 |
def menu():
|
176 |
-
# Handle filter parameters
|
177 |
selected_category = request.args.get("category", "All")
|
178 |
is_veg_only = request.args.get("veg") == 'on'
|
179 |
|
180 |
-
# Prioritize Customized Dish, then Veg, then All
|
181 |
if request.args.get("category") == "Customized Dish":
|
182 |
selected_category = "Customized Dish"
|
183 |
else:
|
184 |
selected_category = "Veg" if is_veg_only else "All"
|
185 |
|
186 |
user_email = session.get('user_email')
|
187 |
-
|
188 |
-
# Handle user authentication
|
189 |
if not user_email:
|
190 |
user_email = request.args.get("email")
|
191 |
user_name = request.args.get("name")
|
@@ -198,8 +193,6 @@ def menu():
|
|
198 |
user_name = session.get('user_name')
|
199 |
|
200 |
first_letter = user_name[0].upper() if user_name else "A"
|
201 |
-
|
202 |
-
# Fetch menu data
|
203 |
ordered_menu, referral_code, reward_points, cart_item_count, most_common_addons, most_common_instructions = fetch_menu_data(selected_category, user_email)
|
204 |
if ordered_menu is None:
|
205 |
return redirect(url_for('login'))
|
@@ -224,14 +217,11 @@ def menu():
|
|
224 |
def search():
|
225 |
selected_category = request.args.get("category", "All")
|
226 |
user_email = session.get('user_email')
|
227 |
-
|
228 |
-
# Handle user authentication
|
229 |
if not user_email:
|
230 |
return redirect(url_for("login"))
|
231 |
user_name = session.get('user_name')
|
232 |
first_letter = user_name[0].upper() if user_name else "A"
|
233 |
|
234 |
-
# Fetch menu data
|
235 |
ordered_menu, referral_code, reward_points, cart_item_count, most_common_addons, most_common_instructions = fetch_menu_data(selected_category, user_email)
|
236 |
if ordered_menu is None:
|
237 |
return redirect(url_for('login'))
|
@@ -250,7 +240,6 @@ def search():
|
|
250 |
def get_addons():
|
251 |
item_name = request.args.get('item_name')
|
252 |
item_section = request.args.get('item_section')
|
253 |
-
|
254 |
if not item_name or not item_section:
|
255 |
return jsonify({"success": False, "error": "Item name and section are required."}), 400
|
256 |
|
@@ -362,9 +351,18 @@ def add_to_cart():
|
|
362 |
})
|
363 |
|
364 |
# Fetch updated cart for UI update
|
365 |
-
cart_query = f"SELECT Name, Quantity__c FROM Cart_Item__c WHERE Customer_Email__c = '{customer_email}'"
|
366 |
cart_result = sf.query_all(cart_query)
|
367 |
-
cart = [{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
368 |
|
369 |
return jsonify({"success": True, "message": "Item added to cart successfully.", "cart": cart})
|
370 |
|
|
|
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,
|
|
|
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 time or order limit to show all custom dishes)
|
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', [])
|
|
|
88 |
item['Video1__c'] = get_valid_video_path(item['Name'])
|
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
|
|
|
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 |
|
|
|
172 |
|
173 |
@menu_blueprint.route("/menu", methods=["GET", "POST"])
|
174 |
def menu():
|
|
|
175 |
selected_category = request.args.get("category", "All")
|
176 |
is_veg_only = request.args.get("veg") == 'on'
|
177 |
|
|
|
178 |
if request.args.get("category") == "Customized Dish":
|
179 |
selected_category = "Customized Dish"
|
180 |
else:
|
181 |
selected_category = "Veg" if is_veg_only else "All"
|
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")
|
|
|
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'))
|
|
|
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'))
|
|
|
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 |
|
|
|
351 |
})
|
352 |
|
353 |
# Fetch updated cart for UI update
|
354 |
+
cart_query = f"SELECT Name, Quantity__c, Price__c, Image1__c, Add_Ons__c, Instructions__c, Category__c, Section__c FROM Cart_Item__c WHERE Customer_Email__c = '{customer_email}'"
|
355 |
cart_result = sf.query_all(cart_query)
|
356 |
+
cart = [{
|
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, "message": "Item added to cart successfully.", "cart": cart})
|
368 |
|