def run(self): # create a product listing carListing = ProductListing("Car", ["car", "Car"]) products = ProductListings() products.addProduct(carListing) carRetrivedFromStore = products.searchForProducts(["car"])[0] if carRetrivedFromStore.name == 'Car': return True
def storeToyAndHaveSonySupply(): # create ps5 product listing toy = ProductListing("Toy", ["Toy"]) products = ProductListings() products.addProduct(toy) toyRetrieved = products.searchForProducts(["Toy"])[0] # create Sony seller sony = Seller("Sony") vendors = Sellers() vendors.addVendor(sony) sonyVendor = vendors.searchVendorByName("Sony") # have sony supply the ps5 toySupply = ProductSupply(20, 100, sonyVendor.id, toyRetrieved.id) sonyVendor.addProductSupplyToCatalog(toySupply)
def run(self): print("--Viewing " + self.productName + "--") productListing = ProductListings().searchForProduct(self.productName) productSupplys = ProductStocks().searchForProductStock( productListing.id) productStockBySellerName = {} supplyTexts = [] for productSupply in productSupplys: seller = Sellers().searchVendorById(productSupply.sellerId) supplyTexts.append(seller.getName() + " - price: $" + str(productSupply.price) + ", " + "stock remaining : " + str(productSupply.quantity)) productStockBySellerName[seller.getName()] = productSupply print(productListing.name + " is available from: ") if len(supplyTexts) == 0: print("No one") else: for supplyText in supplyTexts: print(" " + supplyText) result = False while result == False: result = self.addToBasketOrBack(productStockBySellerName) return result
def run(self): print("--Add Additional Product Stock--") printCatalogList(self.seller) productName = '' productSupply = None while productSupply == None: productName = input( "What is the products name you want to add more stock for?") if productName == 'back': return None productListing = ProductListings().searchForProduct(productName) if productListing != None: catalog = self.seller.getCatalog() for supply in catalog: if supply.productId == productListing.id: productSupply = supply if productSupply is None: print("you do not stock a product with that name") amountToAdd = None while amountToAdd == None: amountToAddInput = input( "What quantity of stock would you like to add?:") if amountToAddInput == 'back': return None if not amountToAddInput.isnumeric(): amountToAdd = None else: amountToAdd = int(amountToAddInput) productSupply.addStock(amountToAdd) print(str(amountToAdd) + " more " + productName + " stock added")
def run(self): print("--" + self.customer.name + "s Basket--") print("Items in basket:") basketItems = self.customer.basket.getItems() if len(basketItems) == 0: print(" Basket empty") else: for productStock in basketItems: productListing = ProductListings().searchFromProductById( productStock.productId) productSeller = Sellers().searchVendorById( productStock.sellerId) print(" " + productListing.name + ": $" + str(productStock.price) + ", ordered from: " + productSeller.getName()) res = '' while res != 'back' and res != 'checkout': res = input("type 'back' or 'checkout': ") if res == 'back': return None elif res == "checkout": if len(basketItems) == 0: print("You have no items in your basket to checkout") self.run() else: return NextState( CheckoutState( self.customer.basket.createOrderDescription(), self.customer.storedPaymentMethod, self.customer), True)
def run(self): storeToyAndHaveSonySupply() sonyVendor = Sellers().searchVendorByName("Sony") toyRetrieved = ProductListings().searchForProducts(["Toy"])[0] fromCatalog = sonyVendor.getCatalog()[0] if fromCatalog.productId == toyRetrieved.id: return True
def printCatalogList(seller): productStocks = seller.getCatalog() if len(productStocks) == 0: print("This seller has no products available") else: for stock in productStocks: productListing = ProductListings().searchFromProductById( stock.productId) print(" " + productListing.name + ", $" + str(stock.price) + ", quantity in stock: " + str(stock.quantity))
def run(self): storeToyAndHaveSonySupply() sonyVendor = Sellers().searchVendorByName("Sony") toyRetrieved = ProductListings().searchForProducts(["Toy"])[0] toyFromCatalog = sonyVendor.getCatalog()[0] customer = storeAdamCustomer() customer.basket.addItem(toyFromCatalog) itemFromBasket = customer.basket.getItems()[0] if itemFromBasket.productId == toyRetrieved.id: return True
def searchProducts(self): print("--Product Search--") keywords = input("Type in keywords to search by: ") if keywords == "back": return None results = ProductListings().searchForProducts(keywords.split(" ")) print("Search Results:") if len(results) != 0: for item in results: print(" " + str(item)) else: print("No results match those keywords") return results
def run(self): print("--Add Product Listing--") name = '' while name == '': name = input("What is the new products name?: ") if name == "back": return None if ProductListings().searchForProduct(name) != None: print("A product with that name already exists") name = '' tagsString = input( "What are the products tags (comma sepereated, i.e phone,samsung,galaxy)?: " ) if tagsString == "back": return None tags = tagsString.split(',') tagsStripped = [x.strip(' ') for x in tags] newProduct = ProductListing(name, tagsStripped) products = ProductListings() products.addProduct(newProduct) print(name + " added to the list of available products")
def run(self): print("--Add To Catalog--") print("the products that can be sold on this site are:") products = ProductListings().getAllListings() for product in products: print(" " + product.name) productName = None productToSell = None while productName == None: productNameInput = input( "What is the name of the product you would like to sell?:") if productNameInput == 'back': return None validName = False for product in products: if product.name == productNameInput: validName = True productToSell = product if validName: productName = productNameInput price = None while price == None: priceInput = input( "What price would you like to sell this product for:") if priceInput == 'back': return None if not priceInput.isnumeric(): price = None else: price = int(priceInput) amountToAdd = None while amountToAdd == None: amountToAddInput = input( "What quantity of stock would you like to add?:") if amountToAddInput == 'back': return None if not amountToAddInput.isnumeric(): amountToAdd = None else: amountToAdd = int(amountToAddInput) productSupply = ProductSupply(price, amountToAdd, self.seller.id, productToSell.id) self.seller.addProductSupplyToCatalog(productSupply) print("You have added " + productName + " to your catalog")
def assertSystemState(): customer = Customers().getCustomerByName("Adam") storeOrder = customer.getOrders()[0] orderedItem = storeOrder.getOrderedItems()[0] xboxProductListing = ProductListings().searchForProducts(["Xbox"])[0] if orderedItem.productStock.productId != xboxProductListing.id: print("Customer has ordered item: False") else: print("Customer has ordered item: True") seller = Sellers().searchVendorByName("Microsoft") sellerOrder = seller.getSellerOrdersLeftToShip()[0] if sellerOrder.orderedItem.productStock.productId != xboxProductListing.id: print("Seller has received an order: False") else: print("Seller has received an order: True")
def customerOrderProductFromSony(): storeToyAndHaveSonySupply() sonyVendor = Sellers().searchVendorByName("Sony") option = DeliveryOption("FastOptTest", 10, sonyVendor.id) sonyVendor.addDeliveryOption(option) optionRetrieved = sonyVendor.getDeliveryOptions()[0] toyRetrieved = ProductListings().searchForProducts(["Toy"])[0] customer = storeAdamCustomer() customer.basket.addItem(toyRetrieved) payment = Payment() payment.applyDiscount(PromoCodes().getPromotion(123)) orderDescription = customer.basket.createOrderDescription() orderDescription.getOrderedItems()[0].setDeliveryOption(optionRetrieved) payment.payForOrder(orderDescription, CardPayment(124124, 14214), "32 Winding Lane")
def run(self): print("--Customer Orders--") ordersPendingDeliver = self.seller.getSellerOrdersLeftToShip() if len(ordersPendingDeliver) == 0: print("There are no pending orders to deliver") else: for order in ordersPendingDeliver: productListing = ProductListings().searchFromProductById( order.orderedItem.productStock.productId) print(" orderID:" + str(order.orderedItem.id) + " " + order.customer.name + " ordered a " + productListing.name + ", delivery option: " + order.orderedItem.deliveryOption.name) stepRes = False while stepRes == False: stepRes = self.handleNextStep(ordersPendingDeliver) return stepRes
def run(self): print("--Product Listings--") allListings = ProductListings().getAllListings() if len(allListings) == 0: print(" There are no product listings") else: print("All products:") for listing in allListings: print(" " + str(listing)) addCommand = "add" posCommands = [addCommand] print("Type either: '" + "' ,'".join(posCommands) + "'") command = '' while command not in posCommands: command = input("What do you want to do?: ") if command == "back": return None if command == addCommand: return NewState(AddProduct(), False)
def run(self): print("--Checkout--") payment = Payment() deliveryAddress = '' while deliveryAddress == '': deliveryAddress = input("Please type your delivery address: ") if deliveryAddress == 'back': return None if deliveryAddress == '': print("Delivery address cannot be empty") print("Now select delivery options for your ordered products") for orderedItem in self.orderDescription.getOrderedItems(): seller = Sellers().searchVendorById( orderedItem.productStock.sellerId) deliveryOptions = seller.getDeliveryOptions() productListing = ProductListings().searchFromProductById( orderedItem.productStock.productId) print("Delivery options for the " + productListing.name + ": ") for deliveryOption in deliveryOptions: print(" " + deliveryOption.name + ", $" + str(deliveryOption.price)) deliveryOption = None while deliveryOption == None: optInput = input( "Type the name of the delivery option to use: ") if optInput == 'back': return None for option in deliveryOptions: if option.name == optInput: deliveryOption = option orderedItem.deliveryOption = deliveryOption usePromoInput = '' while usePromoInput != 'y' and usePromoInput != 'n': usePromoInput = input( "Do you want to use a promotional code (y/n): ") if usePromoInput == "back": return None promoApplied = False if usePromoInput == 'y': validCode = False while validCode == False: codeInput = input("Enter your promotion code: ") if codeInput == "back": return None else: realCode = PromoCodes().getPromotion(codeInput) if realCode != None: payment.applyDiscount(realCode) validCode = True promoApplied = True if promoApplied: print("Total price before promotion: $" + str(self.orderDescription.getTotalPrice())) print("Price after promotion code: $" + str(payment.calculatePriceAfterPromo(self.orderDescription))) else: print("Total price: $" + str(self.orderDescription.getTotalPrice())) useStoredPaymentMethod = False if self.storedPaymentMethod != None: useStored = '' while useStored != 'y' and useStored != 'n': useStored = input( "Do you want to use your stored payment method?(y,n): ") if useStored == "back": return None useStoredPaymentMethod = useStored == 'y' paymentMethod = None toStore = False if not useStoredPaymentMethod: paymentTypeInput = '' while paymentTypeInput != 'credit' and paymentTypeInput != 'debit' and paymentTypeInput != 'paypal': paymentTypeInput = input( "What payment type do you want to use (credit,debit,paypal): " ) if paymentTypeInput == "back": return None if paymentTypeInput == 'credit': paymentMethod = CardPayment(0, 0) if paymentTypeInput == 'debit': paymentMethod = DebitPayment() if paymentTypeInput == 'paypal': paymentMethod = PaypalPayment() toStoreInput = '' while toStoreInput != 'y' and toStoreInput != 'n': toStoreInput = input( "Do you want to store this payment method for future use?(y,n): " ) if toStoreInput == "back": return None if toStoreInput == 'y': toStore = True else: paymentMethod = self.storedPaymentMethod if toStore: #Only store when the payment is complete self.customer.storedPaymentMethod = paymentMethod payment.payForOrder(self.orderDescription, paymentMethod, deliveryAddress) self.customer.basket.clearBasket() print("Payment successful, you have ordered the products!")