File size: 3,130 Bytes
3708f3b
ac72660
3708f3b
78fa2c0
3708f3b
78fa2c0
3708f3b
 
78fa2c0
3708f3b
 
 
 
78fa2c0
3708f3b
 
 
78fa2c0
3708f3b
 
 
 
 
 
 
d5a438f
3708f3b
 
d5a438f
44b1ed4
3708f3b
 
 
44b1ed4
3708f3b
 
44b1ed4
3708f3b
 
44b1ed4
ac72660
3708f3b
 
 
44b1ed4
3708f3b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44b1ed4
 
ac72660
3708f3b
ac72660
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from flask import Blueprint, render_template, request, session, jsonify
from flask import redirect, url_for
from salesforce import get_salesforce_connection

menu_blueprint = Blueprint('menu', __name__)

# Initialize Salesforce connection
sf = get_salesforce_connection()

@menu_blueprint.route("/menu", methods=["GET", "POST"])
def menu():
    selected_category = request.args.get("category", "All")
    user_email = session.get('user_email')

    if not user_email:
        user_email = request.args.get("email")
        user_name = request.args.get("name")

        if user_email:
            session['user_email'] = user_email
            session['user_name'] = user_name  # Store name in session
        else:
            return redirect(url_for("login"))
    else:
        user_name = session.get('user_name')  # Get name from session if it's already stored

    # Get the first letter of the user's name (make it uppercase for consistency)
    first_letter = user_name[0].upper() if user_name else "A"

    try:
        # Fetch user referral and reward points
        user_query = f"SELECT Referral__c, Reward_Points__c FROM Customer_Login__c WHERE Email__c = '{user_email}'"
        user_result = sf.query(user_query)

        if not user_result['records']:
            return redirect(url_for('login'))

        referral_code = user_result['records'][0].get('Referral__c', 'N/A')
        reward_points = user_result['records'][0].get('Reward_Points__c', 0)

        # Query to fetch Menu_Item__c records including Total_Ordered__c for best sellers
        menu_query = """
            SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c, Total_Ordered__c, Video_URL__c
            FROM Menu_Item__c
        """
        result = sf.query(menu_query)
        food_items = result['records'] if 'records' in result else []

        # Ensure Total_Ordered__c has a valid value
        for item in food_items:
            if 'Total_Ordered__c' not in item or item['Total_Ordered__c'] is None:
                item['Total_Ordered__c'] = 0  # Default value

        # Process the food items and include them in the template
        section_order = ["Best Sellers", "Starters", "Biryanis", "Curries", "Breads", "Customized dish", "Apetizer", "Desserts", "Soft Drinks"]
        ordered_menu = {section: [] for section in section_order}

        # Sorting and filtering logic (same as your existing code)

        # Pass the ordered_menu and other data to the template
        return render_template(
            "menu.html",  # Template path
            ordered_menu=ordered_menu,
            categories=["All", "Veg", "Non veg"],
            selected_category=selected_category,
            referral_code=referral_code,
            reward_points=reward_points,
            user_name=user_name,
            first_letter=first_letter
        )

    except Exception as e:
        # Log the error and return the error page with error details
        print(f"Error fetching menu data: {str(e)}")
        return render_template("error.html", error=str(e))  # Render error.html with the error message