-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCart.py
More file actions
134 lines (107 loc) · 5.14 KB
/
Cart.py
File metadata and controls
134 lines (107 loc) · 5.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# for functions to add items, delete items, and checkout, boolean for checked out?
from datetime import datetime
import pandas as pd
from Inventory import Inventory
from Order import Order
import random
class Cart:
def __init__(self, username):
self.Username = username
self.ISBN = None
self.quantity = None
self.CardNumber = str(datetime.today().timestamp())
self.goodList = pd.DataFrame(columns=['ISBN', 'Quantity', 'Price'], dtype=object)
self.check=False
#retrieve card number
def getCardNumber(self):
return self.CardNumber
def AddToCart(self, item, quantity):
price = Inventory().getPrice(item)
if (price == -1):
return "Book does not exist"
self.ISBN = item
self.Quantity = quantity
new_row = pd.Series({"ISBN": item, "Quantity": quantity, "Price": price})
self.goodList = self.goodList.append(new_row, ignore_index=True)
def getQuantity(self):
return self.quantity
def RemoveFromCart(self, isbn):
# df.drop(df.loc[df['line_race'] == 0].index, inplace=True)
self.goodList.drop(self.goodList.loc[self.goodList['ISBN'] == isbn].index, inplace=True)
self.goodList.reset_index(drop=True, inplace=True)
# x = np.array(self.goodList)
# x=x[x[:, 0] != item]
# self.goodList = x.tolist()
# makes an new Order and prints a document
# returns the new order ID which will be added to the user’s orders array
def checkout(self, inventory, order, customer):
if (len(self.goodList.index) == 0):
print("Cart empty - can't checkout")
return
carttotal = 0
#This will calculate the total of the cart.
for i in range(len(self.goodList.index)):
isbn = self.goodList.loc[i].ISBN
quantity = int(self.goodList.loc[i].Quantity)
price = int(self.goodList.loc[i].Price)
total = quantity * price
carttotal = carttotal + total
print("Cart total: $", carttotal)
#Below here, we start adding user payment information.
#This will loop as long as credit card numbers are invalid (aka should only include numbers)
while True:
CardNumber = input("\nInput CardNumber: ")
if CardNumber.isnumeric() == True:
break
elif CardNumber.isnumeric() == False:
print("Invalid Input. Card Number should contain numbers only.")
cardName = input("Name on card: ")
billingAddress = input("Please insert your billing address STREET NUMBER AND STREET NAME: ")
billingCity = input("Please insert billing address CITY: ")
billingState = input("Please insert billing address STATE: ")
billingZIP = int(input("Please insert billing address ZIP: "))
orderNum = random.randint(1, 5000)
for i in range(len(self.goodList.index)):
isbn = self.goodList.loc[i].ISBN
quantity = int(self.goodList.loc[i].Quantity)
price = int(self.goodList.loc[i].Price)
total = quantity * price
order.addNewOrder(CardNumber, cardName, billingAddress, billingCity, billingState, billingZIP, isbn, quantity, price, total, orderNum)
#If the user would like to store the card information for this order
print ("Would you like to store this card information to your account?")
storeCardInfo = input("(Y) Yes\n(N) No\n>>")
if storeCardInfo.lower() == 'y':
customer.EditPaymentInfo(cardName, CardNumber, billingAddress, billingCity, billingState, billingZIP)
self.check = True
self.goodList = pd.DataFrame(columns=['ISBN', 'Quantity'], dtype=object)
order.save2file()
print("\n------Checkout Successful------")
#If the user deletes something from their cart, this will add it back to inventory -- takes away the reservation.
def InventoryCheck(self, isbn):
for i in range(len(self.goodList.index)):
if (self.goodList.loc[i].ISBN == isbn):
return self.goodList.loc[i].Quantity
return 0
def addback(self, inventory, isbn, quantity):
for i in range(len(self.goodList.index)):
if (self.goodList.loc[i].ISBN == isbn):
inventory.addQuantity(isbn, quantity)
def AddBackToInventory(self, inventory):
for i in range(len(self.goodList.index)):
isbn = self.goodList.loc[i].ISBN
quantity = int(self.goodList.loc[i].Quantity)
inventory.addQuantity(isbn, quantity)
def isCheck(self):
return self.check
def CartCheck(self):
if (len(self.goodList.index) == 0):
return False
else:
return True
def print(self):
if len(self.goodList) > 0:
print("\n#######Cart List################")
print(self.goodList)
print('################################')
else:
print("\n-------------------------Cart is Empty-----------------------")