def remove_item(username): number = int(input("Item number: ")) if number < 1 or number > db.getItemCount(username): print("The cart does not contain an item " + "with that number.\n") else: cart = Cart(username) item = [] item = cart.removeItem(number-1) #delete in db db.deleteItemCart(username,item[0].product,item[0].quantity) print("Item" + number + "was deleted.\n")
def add_item(products, username): number = int(input("Item number: ")) quantity = int(input("Quantity: ")) if number < 1 or number > len(products): print("No product has that number.\n") else: cart = Cart(username) product = products[number-1] item = LineItem(product, quantity) cart.addItem(item) #put in db db.addItemtoCart(username, product.name, quantity) print(product.name + " was added.\n")
def show_cart(username): if db.getItemCount(username) == 0: print("There are no items in your cart.\n") else: line_format1 = "{:<5s} {:<20s} {:>12s} {:>10s} {:>10s}" line_format2 = "{:<5d} {:<20s} {:>12.2f} {:>10d} {:>10.2f}" print(line_format1.format("Item", "Name", "Your Price", "Quantity", "Total")) i = 0 total = 0 cart = Cart(username) detail = Product() for item in cart: detail = db.getProductDetail(item.product) total += item.getTotalItem(detail.getDiscountPrice()) print(line_format2.format(i+1, detail.name, detail.getDiscountPrice(), item.quantity, item.getTotalItem(detail.getDiscountPrice()) )) i += 1 print("{:>66.2f}".format(total)) print()
def modItem(username): number = int(input("Item number: ")) cart = Cart(username) if number < 1 or number > db.getItemCount(username): print("The cart does not contain an item " + "with that number.\n") else: mod = int(input("Change the quantity to: ")) if mod > 0: item = [] item = cart.modItem(number-1) #modify in db db.modifyItemCart(username, item[0].product, item[0].quantity, mod) else: print("Invalid number.\n")
def main(): show_title() show_menu() # get a list of Product objects and display them products = db.get_products() show_products(products) # create a Cart object to store LineItem objects cart = Cart() while True: command = input("Command: ") if command == "cart": show_cart(cart) elif command == "add": add_item(cart, products) elif command == "del": remove_item(cart) elif command == "exit": print("Bye!") break else: print("Not a valid command. Please try again.\n")
import db from business import Product, LineItem, Cart products = db.get_products() product = products[1] lineItem = LineItem(product, 2) cart = Cart() cart.addItem(lineItem) print("Product: ", product.name) print("Price: ", product.getDiscountPrice()) print("Quantity: ", lineItem.quantity) print("Total: ", cart.getTotal())
self.makeButtons() for child in self.winfo_children(): child.grid_configure(padx=5, pady=3) def makeButtons(self): # Create a frame to store the two buttons buttonFrame = ttk.Frame(self) # Add the button frame to the bottom row of the main grid buttonFrame.grid(column=4, row=12, columnspan=1, sticky=tk.E) # Add two buttons to the button frame ttk.Button(buttonFrame, text="Add to Cart",) \ .grid(column=0, row=0, padx=5) def checkout(self): db.updateproducts() if __name__ == "__main__": cart = Cart() root = tk.Tk() root.title("Harry Pickle's Delightful Surprise") shoppingIndex(root) root.mainloop()