Spaces:
Running
Running
Create cart.py
Browse files- models/cart.py +15 -0
models/cart.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
cart = []
|
2 |
+
|
3 |
+
def add_to_cart(name, price):
|
4 |
+
global cart
|
5 |
+
cart.append({"Name": name, "Price": price, "Quantity": 1})
|
6 |
+
return cart
|
7 |
+
|
8 |
+
def view_cart():
|
9 |
+
global cart
|
10 |
+
total = sum(float(item["Price"]) * item["Quantity"] for item in cart)
|
11 |
+
return cart, total
|
12 |
+
|
13 |
+
def clear_cart():
|
14 |
+
global cart
|
15 |
+
cart = []
|