-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
252 lines (208 loc) · 8.7 KB
/
main.py
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
from cart import cart
from order import order
from user import user
from database import *
from item import item
#Notes about program
#Forgot about showing stock quantity to user code became to big and complex to implement later
#this means that stock is not shown between purchases
#Further Documentation
#The user currently has to type the item they want to remove
#adding and removing is done one at a time
#because stock was not exposed to the user, neither was quantity
#so removing an item only removes the first one.
#a warning is printed before doing so
#Read in username and password from user
username = input("Enter your username: ")
password = input("Enter your password: ")
#order number
oNum = 0
total = 0
items = []
#create shopping cart
scart = cart()
#forward the username and password to login function which should check the database
login(username, password)
#create user
customer = user(username, password)
loop_flag = True
#start infinite loop
while (loop_flag):
#ask user to select a category
print("Categories")
print("1. for Household items")
print("2. for Books")
print("3. for Toys")
print("4. for Small Electronics")
print("5. to Show Cart")
print("6. Remove from Cart")
print("7. Finalize order")
print("8. Show Order History")
print("9. Logout")
answer = str(input("Pick a Category 1-4 to add to cart or 5-7 for cart operations: "))
#verify category
if (answer == "1"):
#ask what item they want
print("---Items for Sale---")
print("1. aluminum foil")
print("2. toothpaste")
print("3. salt")
print("4. pepper")
selection = str(input("Pick an item 1-4: "))
#append to cart
if (selection == "1"):
#temporary item used to get price of an item
stuff = item("aluminum foil")
if (scart.addItem(stuff) == False):
print("Sorry we are all out of that item at the moment")
elif (selection == "2"):
#temporary item used to get price of an item
stuff = item("toothpaste")
if (scart.addItem(stuff) == False):
print("Sorry we are all out of that item at the moment")
elif (selection == "3"):
#temporary item used to get price of an item
stuff = item("salt")
if (scart.addItem(stuff) == False):
print("Sorry we are all out of that item at the moment")
elif (selection == "4"):
#temporary item used to get price of an item
stuff = item("pepper")
if (scart.addItem(stuff) == False):
print("Sorry we are all out of that item at the moment")
elif (answer == "2"):
#ask what item they want
print("---Items for Sale---")
print("1. Harry Potter Book")
print("2. SW Design Book")
print("3. Spiderman Book")
print("4. Diary of a Wimpy Kid Book")
selection = str(input("Pick an item 1-4: "))
#append to cart
if (selection == "1"):
#temporary item used to get price of an item
stuff = item("Harry Potter Book")
if (scart.addItem(stuff) == False):
print("Sorry we are all out of that item at the moment")
elif (selection == "2"):
#temporary item used to get price of an item
stuff = item("SW Design Book")
if (scart.addItem(stuff) == False):
print("Sorry we are all out of that item at the moment")
elif (selection == "3"):
#temporary item used to get price of an item
stuff = item("Spiderman Book")
if (scart.addItem(stuff) == False):
print("Sorry we are all out of that item at the moment")
elif (selection == "4"):
#temporary item used to get price of an item
stuff = item("Diary of a Wimpy Kid Book")
if (scart.addItem(stuff) == False):
print("Sorry we are all out of that item at the moment")
elif (answer == "3"):
#ask what item they want
print("---Items for Sale---")
print("1. Spiderman Figure")
print("2. Superman Figure")
print("3. Pikachu Plushy")
print("4. Charizard Card")
selection = str(input("Pick an item 1-4: "))
#append to cart
if (selection == "1"):
#temporary item used to get price of an item
stuff = item("Spiderman Figure")
if (scart.addItem(stuff) == False):
print("Sorry we are all out of that item at the moment")
elif (selection == "2"):
#temporary item used to get price of an item
stuff = item("Superman Figure")
if (scart.addItem(stuff) == False):
print("Sorry we are all out of that item at the moment")
elif (selection == "3"):
#temporary item used to get price of an item
stuff = item("Pikachu Plushy")
if (scart.addItem(stuff) == False):
print("Sorry we are all out of that item at the moment")
elif (selection == "4"):
#temporary item used to get price of an item
stuff = item("Charizard Card")
if (scart.addItem(stuff) == False):
print("Sorry we are all out of that item at the moment")
elif (answer == "4"):
#ask what item they want
print("---Items for Sale---")
print("1. Phone")
print("2. Camera")
print("3. Tablet")
print("4. Laptop")
selection = str(input("Pick an item 1-4: "))
#append to cart
if (selection == "1"):
#temporary item used to get price of an item
stuff = item("Phone")
if (scart.addItem(stuff) == False):
print("Sorry we are all out of that item at the moment")
elif (selection == "2"):
#temporary item used to get price of an item
stuff = item("Camera")
if (scart.addItem(stuff) == False):
print("Sorry we are all out of that item at the moment")
elif (selection == "3"):
#temporary item used to get price of an item
stuff = item("Tablet")
if (scart.addItem(stuff) == False):
print("Sorry we are all out of that item at the moment")
elif (selection == "4"):
#temporary item used to get price of an item
stuff = item("Laptop")
if (scart.addItem(stuff) == False):
print("Sorry we are all out of that item at the moment")
#print contents of the cart along with total
elif (answer == "5"):
scart.showCart()
elif (answer == "6"):
scart.showCart()
print("Note: if the item appears twice. Only the first one will be removed.")
removal = str(input("Type the whole name of the item to be removed: "))
scart.rmItem(removal)
scart.showCart()
elif (answer == "7"):
#create order
oNum += 1
total = scart.getTotal()
items = scart.getItems()
while (True):
#have them enter in their address if they have
if ((customer.getAddress() == "") or (customer.getPayment() == "")):
customer.setAddress(str(input("Enter your address: ")))
#have them enter in their payment if they haven't already
if (customer.setPayment(str(input("Enter your credit card number: ")))):
print("---Confirm Purchase---")
confirmPurchase = str(input("Type yes to confirm otherwise type no: "))
#make the customer confirm their purchase
if confirmPurchase == "yes":
purchase = order(customer,total, items, oNum)
purchase.orderHistory()
scart.emptyCart()
else:
oNum -= 1
break
else:
#make the customer confirm their purchase
print("---Confirm Purchase---")
confirmPurchase = str(input("Type yes to confirm otherwise type no: "))
if confirmPurchase == "yes":
purchase = order(customer, total, items, oNum)
purchase.orderHistory()
scart.emptyCart()
else:
oNum -= 1
break
elif (answer == "8"):
#do stuff
tmpOrder = order(None, total, items, oNum)
tmpOrder.showHistory()
elif (answer == "9"):
#logout
print("Thanks for shopping with us")
quit()