Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -128,31 +128,7 @@ def menu():
|
|
| 128 |
|
| 129 |
)
|
| 130 |
|
| 131 |
-
"""
|
| 132 |
-
@app.route("/menu", methods=["GET", "POST"])
|
| 133 |
-
def menu():
|
| 134 |
-
selected_category = request.args.get("category", "All")
|
| 135 |
-
user_id = session.get('user_id')
|
| 136 |
-
print(f"Cookies on /menu: {request.cookies}") # Debug: Check cookies sent
|
| 137 |
-
print(f"Session check in /menu: user_id={user_id}")
|
| 138 |
|
| 139 |
-
if not user_id:
|
| 140 |
-
print("Session missing, redirecting to login.")
|
| 141 |
-
return redirect(url_for('login'))
|
| 142 |
-
|
| 143 |
-
try:
|
| 144 |
-
query = "SELECT Name, Price__c, Image1__c, Image2__c, Category__c, Description__c FROM Menu_Item__c"
|
| 145 |
-
result = sf.query(query)
|
| 146 |
-
food_items = result['records'] if 'records' in result else []
|
| 147 |
-
categories = {item['Category__c'] for item in food_items if 'Category__c' in item}
|
| 148 |
-
if selected_category != "All":
|
| 149 |
-
food_items = [item for item in food_items if item.get("Category__c") == selected_category]
|
| 150 |
-
except Exception as e:
|
| 151 |
-
print(f"Error fetching menu data: {str(e)}")
|
| 152 |
-
food_items = []
|
| 153 |
-
categories = []
|
| 154 |
-
return render_template("menu.html", food_items=food_items, categories=categories, selected_category=selected_category)
|
| 155 |
-
"""
|
| 156 |
|
| 157 |
|
| 158 |
@app.route("/cart", methods=["GET"])
|
|
@@ -167,6 +143,9 @@ def cart():
|
|
| 167 |
WHERE Customer_Email__c = '{email}'
|
| 168 |
""")
|
| 169 |
cart_items = result.get("records", [])
|
|
|
|
|
|
|
|
|
|
| 170 |
subtotal = sum(item['Quantity__c'] * item['Price__c'] for item in cart_items)
|
| 171 |
except Exception as e:
|
| 172 |
print(f"Error fetching cart items: {e}")
|
|
@@ -207,7 +186,7 @@ def add_to_cart():
|
|
| 207 |
"Name": item_name,
|
| 208 |
"Price__c": item_price,
|
| 209 |
"Quantity__c": 1,
|
| 210 |
-
"Add_Ons__c": ";".join(addons) if addons else None,
|
| 211 |
"Image1__c": item_image,
|
| 212 |
"Customer_Email__c": customer_email, # Associate with the logged-in user
|
| 213 |
|
|
@@ -339,8 +318,9 @@ def checkout():
|
|
| 339 |
[f"{item['Name']} (Qty: {item['Quantity__c']})" for item in cart_items]
|
| 340 |
),
|
| 341 |
"Add_Ons__c": "\n".join(
|
| 342 |
-
[
|
| 343 |
),
|
|
|
|
| 344 |
}
|
| 345 |
sf.Order__c.create(order_data)
|
| 346 |
for item in cart_items:
|
|
|
|
| 128 |
|
| 129 |
)
|
| 130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
|
| 134 |
@app.route("/cart", methods=["GET"])
|
|
|
|
| 143 |
WHERE Customer_Email__c = '{email}'
|
| 144 |
""")
|
| 145 |
cart_items = result.get("records", [])
|
| 146 |
+
for item in cart_items:
|
| 147 |
+
item['Add_Ons__c'] = item.get('Add_Ons__c', "None")
|
| 148 |
+
|
| 149 |
subtotal = sum(item['Quantity__c'] * item['Price__c'] for item in cart_items)
|
| 150 |
except Exception as e:
|
| 151 |
print(f"Error fetching cart items: {e}")
|
|
|
|
| 186 |
"Name": item_name,
|
| 187 |
"Price__c": item_price,
|
| 188 |
"Quantity__c": 1,
|
| 189 |
+
"Add_Ons__c": ";".join(addons) if addons and isinstance(addons, list) else "None",
|
| 190 |
"Image1__c": item_image,
|
| 191 |
"Customer_Email__c": customer_email, # Associate with the logged-in user
|
| 192 |
|
|
|
|
| 318 |
[f"{item['Name']} (Qty: {item['Quantity__c']})" for item in cart_items]
|
| 319 |
),
|
| 320 |
"Add_Ons__c": "\n".join(
|
| 321 |
+
[item['Add_Ons__c'] if item.get('Add_Ons__c') else "None" for item in cart_items]
|
| 322 |
),
|
| 323 |
+
|
| 324 |
}
|
| 325 |
sf.Order__c.create(order_data)
|
| 326 |
for item in cart_items:
|