Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -131,7 +131,7 @@ def menu():
|
|
131 |
def cart():
|
132 |
email = session.get('user_email') # Get logged-in user's email
|
133 |
if not email:
|
134 |
-
return redirect(url_for("login"))
|
135 |
|
136 |
try:
|
137 |
# Query cart items
|
@@ -141,20 +141,13 @@ def cart():
|
|
141 |
WHERE Customer_Email__c = '{email}'
|
142 |
""")
|
143 |
cart_items = result.get("records", [])
|
144 |
-
|
145 |
-
# Calculate the subtotal, including add-ons prices
|
146 |
subtotal = sum(item['Price__c'] * item['Quantity__c'] for item in cart_items)
|
147 |
|
148 |
-
|
149 |
-
for item in cart_items:
|
150 |
-
item['Add_Ons__c'] = item.get('Add_Ons__c', "None") # Default to "None" if no add-ons
|
151 |
-
|
152 |
except Exception as e:
|
153 |
print(f"Error fetching cart items: {e}")
|
154 |
-
cart_items
|
155 |
-
subtotal = 0
|
156 |
|
157 |
-
return render_template("cart.html", cart_items=cart_items, subtotal=subtotal)
|
158 |
|
159 |
|
160 |
@app.route('/cart/add', methods=['POST'])
|
@@ -263,18 +256,21 @@ def get_addons():
|
|
263 |
except Exception as e:
|
264 |
print(f"Error fetching add-ons: {e}")
|
265 |
return jsonify({"success": False, "error": "Unable to fetch add-ons. Please try again later."})
|
266 |
-
|
267 |
@app.route("/cart/update_quantity", methods=["POST"])
|
268 |
def update_quantity():
|
269 |
-
data = request.json
|
|
|
|
|
270 |
email = data.get('email') # Customer email
|
271 |
item_name = data.get('item_name') # Item name
|
272 |
quantity = data.get('quantity') # New quantity
|
273 |
|
274 |
-
# Validate inputs
|
275 |
if not email or not item_name or quantity is None:
|
276 |
return jsonify({"success": False, "error": "Email, item name, and quantity are required."}), 400
|
277 |
|
|
|
|
|
|
|
278 |
try:
|
279 |
# Query the cart item in Salesforce
|
280 |
cart_items = sf.query(
|
|
|
131 |
def cart():
|
132 |
email = session.get('user_email') # Get logged-in user's email
|
133 |
if not email:
|
134 |
+
return redirect(url_for("login"))
|
135 |
|
136 |
try:
|
137 |
# Query cart items
|
|
|
141 |
WHERE Customer_Email__c = '{email}'
|
142 |
""")
|
143 |
cart_items = result.get("records", [])
|
|
|
|
|
144 |
subtotal = sum(item['Price__c'] * item['Quantity__c'] for item in cart_items)
|
145 |
|
146 |
+
return render_template("cart.html", cart_items=cart_items, subtotal=subtotal, customer_email=email)
|
|
|
|
|
|
|
147 |
except Exception as e:
|
148 |
print(f"Error fetching cart items: {e}")
|
149 |
+
return render_template("cart.html", cart_items=[], subtotal=0)
|
|
|
150 |
|
|
|
151 |
|
152 |
|
153 |
@app.route('/cart/add', methods=['POST'])
|
|
|
256 |
except Exception as e:
|
257 |
print(f"Error fetching add-ons: {e}")
|
258 |
return jsonify({"success": False, "error": "Unable to fetch add-ons. Please try again later."})
|
|
|
259 |
@app.route("/cart/update_quantity", methods=["POST"])
|
260 |
def update_quantity():
|
261 |
+
data = request.json
|
262 |
+
print(f"Incoming request data: {data}") # Debug log
|
263 |
+
|
264 |
email = data.get('email') # Customer email
|
265 |
item_name = data.get('item_name') # Item name
|
266 |
quantity = data.get('quantity') # New quantity
|
267 |
|
|
|
268 |
if not email or not item_name or quantity is None:
|
269 |
return jsonify({"success": False, "error": "Email, item name, and quantity are required."}), 400
|
270 |
|
271 |
+
# The rest of the logic remains the same
|
272 |
+
|
273 |
+
|
274 |
try:
|
275 |
# Query the cart item in Salesforce
|
276 |
cart_items = sf.query(
|