Beispiel #1
0
    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
Beispiel #2
0
    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)
Beispiel #3
0
 def run(self):
     # create Sony seller
     sony = Seller("Sony")
     sellers = Sellers()
     sellers.addVendor(sony)
     seller = sellers.searchVendorByName("Sony")
     if seller.getName() == 'Sony':
         return True
Beispiel #4
0
 def run(self):
     customerOrderProductFromSony()
     sonyVendor = Sellers().searchVendorByName("Sony")
     orderedItem = sonyVendor.getSellerOrdersLeftToShip()[0].orderedItem
     orderedItem.setShipped()
     itemsRemaining = sonyVendor.getSellerOrdersLeftToShip()
     if len(itemsRemaining) == 0:
         return True
Beispiel #5
0
 def run(self):
     storeToyAndHaveSonySupply()
     sonyVendor = Sellers().searchVendorByName("Sony")
     option = DeliveryOption("FastOptTest", 10, sonyVendor.id)
     sonyVendor.addDeliveryOption(option)
     optionRetrieved = sonyVendor.getDeliveryOptions()[0]
     if optionRetrieved.name == "FastOptTest":
         return True
Beispiel #6
0
    def run(self):
        storeToyAndHaveSonySupply()
        sonyVendor = Sellers().searchVendorByName("Sony")
        toyRetrieved = ProductListings().searchForProducts(["Toy"])[0]

        fromCatalog = sonyVendor.getCatalog()[0]
        if fromCatalog.productId == toyRetrieved.id:
            return True
Beispiel #7
0
 def run(self):
     try:
         seller = Seller("Adam")
         Sellers().addSeller(seller)
         Sellers().addSeller(seller)
     except:
         return True
     return False
Beispiel #8
0
 def payForVendorsOrders(self, storeOrderDescription):
     """This function pays the required sellers for orders
     pre-condition:The store order description should be passed in as an argument
     post-condition:Payments are made to the relevant sellers accounts"""
     for orderdItem in storeOrderDescription.getOrderedItems():
         sellers = Sellers()
         vendor = sellers.searchVendorById(orderdItem.productStock.sellerId)
         vendor.payForItemSale(orderdItem.productStock.price)
Beispiel #9
0
    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
Beispiel #10
0
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)
Beispiel #11
0
    def addToBasketOrBack(self, productStockBySellerName):
        orderText = input(
            "type either 'order from name' or 'view *sellers name*': ")
        if orderText == 'back':
            return None

        if orderText.startswith("view") and len(orderText) > len("view"):
            sellerName = orderText.split("view")[1].strip()
            seller = Sellers().searchVendorByName(sellerName)
            if seller != None:
                return NextState(SellerCatalogState(seller), False)

        elif orderText.startswith(
                "order from") and len(orderText) > len("order from"):
            sellerName = orderText.split("order from")[1].strip()

            productSupplyToOrder = productStockBySellerName.get(
                sellerName, None)
            if productSupplyToOrder == None:
                print("Invalid Seller name")
                return False

            self.customer.basket.addItem(productSupplyToOrder)

            print("A " + self.productName + " from the seller " + sellerName +
                  " has been added to your basket, " +
                  "proceed to the check out when you are ready")
Beispiel #12
0
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")
Beispiel #13
0
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("--Seller Login--")
        currentSeller = None
        doesSellerHaveAccount = ''
        while doesSellerHaveAccount != 'y' and doesSellerHaveAccount != 'n':
            doesSellerHaveAccount = input("Do you have an account (y/n): ")
            if doesSellerHaveAccount == "back":
                return None

        if doesSellerHaveAccount == 'y':
            seller = None
            while seller == None:
                username = input("What is your account name: ")
                if username == "back":
                    return None
                seller = Sellers().searchVendorByName(username)
                if seller == None:
                    print("Account does not exist")
            currentSeller = seller
        else:
            newAccountName = ''
            while newAccountName == '':
                newAccountName = input("Enter a name for your new account: ")
                if Sellers().searchVendorByName(newAccountName) != None:
                    print(
                        "An account with that name already exists, please use a different name"
                    )
                    newAccountName = ''
                if newAccountName == "back":
                    return None

            newSeller = Seller(newAccountName)
            Sellers().addVendor(newSeller)
            currentSeller = newSeller
            print("Account Created")

        return aNewState(SellerAccountState(currentSeller), False)
Beispiel #15
0
    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!")