Spaces:
Sleeping
Sleeping
Update cart.py
Browse files
cart.py
CHANGED
|
@@ -2,7 +2,7 @@ from flask import Blueprint, render_template, request, session
|
|
| 2 |
import random
|
| 3 |
|
| 4 |
cart_blueprint = Blueprint('cart', __name__)
|
| 5 |
-
@
|
| 6 |
def cart():
|
| 7 |
email = session.get('user_email')
|
| 8 |
if not email:
|
|
@@ -103,7 +103,7 @@ def cart():
|
|
| 103 |
print(f"Error fetching cart items: {e}")
|
| 104 |
return render_template("cart.html", cart_items=[], subtotal=0, reward_points=0, coupons=[], suggestions=[])
|
| 105 |
|
| 106 |
-
@
|
| 107 |
def add_suggestion_to_cart():
|
| 108 |
try:
|
| 109 |
# Get data from the request
|
|
@@ -181,7 +181,7 @@ def add_suggestion_to_cart():
|
|
| 181 |
except Exception as e:
|
| 182 |
print(f"Error adding item to cart: {str(e)}")
|
| 183 |
return jsonify({"success": False, "error": str(e)})
|
| 184 |
-
@
|
| 185 |
def remove_cart_item(item_name):
|
| 186 |
try:
|
| 187 |
customer_email = session.get('user_email')
|
|
@@ -200,7 +200,7 @@ def remove_cart_item(item_name):
|
|
| 200 |
except Exception as e:
|
| 201 |
print(f"Error: {str(e)}")
|
| 202 |
return jsonify({'success': False, 'message': f"An error occurred: {str(e)}"}), 500
|
| 203 |
-
@
|
| 204 |
def update_quantity():
|
| 205 |
data = request.json # Extract JSON data from the request
|
| 206 |
email = data.get('email')
|
|
@@ -256,7 +256,7 @@ def update_quantity():
|
|
| 256 |
print(f"Error updating quantity: {str(e)}")
|
| 257 |
return jsonify({"success": False, "error": str(e)}), 500
|
| 258 |
|
| 259 |
-
@
|
| 260 |
def checkout():
|
| 261 |
email = session.get('user_email')
|
| 262 |
user_id = session.get('user_name')
|
|
|
|
| 2 |
import random
|
| 3 |
|
| 4 |
cart_blueprint = Blueprint('cart', __name__)
|
| 5 |
+
@cart_blueprint.route("/cart", methods=["GET"])
|
| 6 |
def cart():
|
| 7 |
email = session.get('user_email')
|
| 8 |
if not email:
|
|
|
|
| 103 |
print(f"Error fetching cart items: {e}")
|
| 104 |
return render_template("cart.html", cart_items=[], subtotal=0, reward_points=0, coupons=[], suggestions=[])
|
| 105 |
|
| 106 |
+
@cart_blueprint.route("/cart/add_suggestion_to_cart", methods=["POST"])
|
| 107 |
def add_suggestion_to_cart():
|
| 108 |
try:
|
| 109 |
# Get data from the request
|
|
|
|
| 181 |
except Exception as e:
|
| 182 |
print(f"Error adding item to cart: {str(e)}")
|
| 183 |
return jsonify({"success": False, "error": str(e)})
|
| 184 |
+
@cart_blueprint.route('/cart/remove/<item_name>', methods=['POST'])
|
| 185 |
def remove_cart_item(item_name):
|
| 186 |
try:
|
| 187 |
customer_email = session.get('user_email')
|
|
|
|
| 200 |
except Exception as e:
|
| 201 |
print(f"Error: {str(e)}")
|
| 202 |
return jsonify({'success': False, 'message': f"An error occurred: {str(e)}"}), 500
|
| 203 |
+
@cart_blueprint.route("/cart/update_quantity", methods=["POST"])
|
| 204 |
def update_quantity():
|
| 205 |
data = request.json # Extract JSON data from the request
|
| 206 |
email = data.get('email')
|
|
|
|
| 256 |
print(f"Error updating quantity: {str(e)}")
|
| 257 |
return jsonify({"success": False, "error": str(e)}), 500
|
| 258 |
|
| 259 |
+
@cart_blueprint.route("/checkout", methods=["POST"])
|
| 260 |
def checkout():
|
| 261 |
email = session.get('user_email')
|
| 262 |
user_id = session.get('user_name')
|