Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -121,31 +121,36 @@ def login(): | |
| 121 | 
             
            def menu():
         | 
| 122 | 
             
                selected_category = request.args.get("category", "All")
         | 
| 123 | 
             
                user_id = session.get('user_id')
         | 
| 124 | 
            -
                 | 
| 125 | 
            -
                print(f"Session check in /menu: user_id={user_id}")
         | 
| 126 |  | 
| 127 | 
            -
                # Get the selected category from the query parameter, default is "All"
         | 
| 128 | 
            -
                selected_category = request.args.get("category", "All")
         | 
| 129 | 
            -
                print(f"Selected category: {selected_category}")
         | 
| 130 | 
             
                if not user_id:
         | 
| 131 | 
             
                    print("Session missing, redirecting to login.")
         | 
| 132 | 
             
                    return redirect(url_for('login'))
         | 
| 133 |  | 
| 134 | 
            -
             | 
| 135 | 
             
                try:
         | 
| 136 | 
            -
                     | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 137 | 
             
                        SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c 
         | 
| 138 | 
             
                        FROM Menu_Item__c
         | 
| 139 | 
             
                    """
         | 
| 140 | 
            -
                     | 
| 141 | 
            -
                    result = sf.query(query)
         | 
| 142 | 
            -
             | 
| 143 | 
            -
                    # Fetch all food items from the query result
         | 
| 144 | 
             
                    food_items = result['records'] if 'records' in result else []
         | 
| 145 |  | 
| 146 | 
            -
                    #  | 
| 147 | 
             
                    categories = {item.get("Veg_NonVeg__c").capitalize() for item in food_items if item.get("Veg_NonVeg__c")}
         | 
| 148 | 
            -
                    categories = {"Veg", "Non-Veg"}  #  | 
| 149 |  | 
| 150 | 
             
                    # Filter food items based on the selected category
         | 
| 151 | 
             
                    if selected_category == "Veg":
         | 
| @@ -157,15 +162,19 @@ def menu(): | |
| 157 | 
             
                    print(f"Error fetching menu data: {str(e)}")
         | 
| 158 | 
             
                    food_items = []
         | 
| 159 | 
             
                    categories = {"All", "Veg", "Non-Veg"}  # Default categories on error
         | 
|  | |
|  | |
| 160 |  | 
| 161 | 
            -
                # Render the menu page with the  | 
| 162 | 
             
                return render_template(
         | 
| 163 | 
             
                    "menu.html",
         | 
| 164 | 
             
                    food_items=food_items,
         | 
| 165 | 
             
                    categories=sorted(categories),  # Sort categories alphabetically if needed
         | 
| 166 | 
             
                    selected_category=selected_category,
         | 
| 167 | 
            -
             | 
|  | |
| 168 | 
             
                )
         | 
|  | |
| 169 | 
             
            @app.route("/cart", methods=["GET"])
         | 
| 170 | 
             
            def cart():
         | 
| 171 | 
             
                email = session.get('user_email')  # Get logged-in user's email
         | 
|  | |
| 121 | 
             
            def menu():
         | 
| 122 | 
             
                selected_category = request.args.get("category", "All")
         | 
| 123 | 
             
                user_id = session.get('user_id')
         | 
| 124 | 
            +
                user_email = session.get('user_email')  # Fetch the user's email
         | 
| 125 | 
            +
                print(f"Session check in /menu: user_id={user_id}, user_email={user_email}")
         | 
| 126 |  | 
|  | |
|  | |
|  | |
| 127 | 
             
                if not user_id:
         | 
| 128 | 
             
                    print("Session missing, redirecting to login.")
         | 
| 129 | 
             
                    return redirect(url_for('login'))
         | 
| 130 |  | 
|  | |
| 131 | 
             
                try:
         | 
| 132 | 
            +
                    # Fetch the user's Referral__c and Reward_Points__c
         | 
| 133 | 
            +
                    user_query = f"SELECT Referral__c, Reward_Points__c FROM Customer_Login__c WHERE Email__c = '{user_email}'"
         | 
| 134 | 
            +
                    user_result = sf.query(user_query)
         | 
| 135 | 
            +
             | 
| 136 | 
            +
                    if not user_result['records']:
         | 
| 137 | 
            +
                        print("User not found!")
         | 
| 138 | 
            +
                        return redirect(url_for('login'))
         | 
| 139 | 
            +
             | 
| 140 | 
            +
                    referral_code = user_result['records'][0].get('Referral__c', 'N/A')  # Default to 'N/A' if empty
         | 
| 141 | 
            +
                    reward_points = user_result['records'][0].get('Reward_Points__c', 0)  # Default to 0 if empty
         | 
| 142 | 
            +
             | 
| 143 | 
            +
                    # Query to fetch menu items
         | 
| 144 | 
            +
                    menu_query = """
         | 
| 145 | 
             
                        SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c 
         | 
| 146 | 
             
                        FROM Menu_Item__c
         | 
| 147 | 
             
                    """
         | 
| 148 | 
            +
                    result = sf.query(menu_query)
         | 
|  | |
|  | |
|  | |
| 149 | 
             
                    food_items = result['records'] if 'records' in result else []
         | 
| 150 |  | 
| 151 | 
            +
                    # Filter categories dynamically
         | 
| 152 | 
             
                    categories = {item.get("Veg_NonVeg__c").capitalize() for item in food_items if item.get("Veg_NonVeg__c")}
         | 
| 153 | 
            +
                    categories = {"Veg", "Non-Veg"}  # Ensure valid categories only
         | 
| 154 |  | 
| 155 | 
             
                    # Filter food items based on the selected category
         | 
| 156 | 
             
                    if selected_category == "Veg":
         | 
|  | |
| 162 | 
             
                    print(f"Error fetching menu data: {str(e)}")
         | 
| 163 | 
             
                    food_items = []
         | 
| 164 | 
             
                    categories = {"All", "Veg", "Non-Veg"}  # Default categories on error
         | 
| 165 | 
            +
                    referral_code = 'N/A'
         | 
| 166 | 
            +
                    reward_points = 0
         | 
| 167 |  | 
| 168 | 
            +
                # Render the menu page with the fetched data
         | 
| 169 | 
             
                return render_template(
         | 
| 170 | 
             
                    "menu.html",
         | 
| 171 | 
             
                    food_items=food_items,
         | 
| 172 | 
             
                    categories=sorted(categories),  # Sort categories alphabetically if needed
         | 
| 173 | 
             
                    selected_category=selected_category,
         | 
| 174 | 
            +
                    referral_code=referral_code,
         | 
| 175 | 
            +
                    reward_points=reward_points
         | 
| 176 | 
             
                )
         | 
| 177 | 
            +
             | 
| 178 | 
             
            @app.route("/cart", methods=["GET"])
         | 
| 179 | 
             
            def cart():
         | 
| 180 | 
             
                email = session.get('user_email')  # Get logged-in user's email
         |