Ejemplo n.º 1
0
    def testAddProductAsAnonymousAndMember(self):
        """Proves that a member will overtake the cart items, which he has added,
        as anonymous user.
        """
        self.logout()

        view = getMultiAdapter((self.shop.products.product_2,
                                self.shop.products.product_2.REQUEST),
                               name="addToCart")
        view.addToCart()

        cart = ICartManagement(self.shop).getCart()
        items = IItemManagement(cart).getItems()
        self.assertEqual(len(items), 1)

        view.addToCart()

        items = IItemManagement(cart).getItems()
        self.assertEqual(len(items), 1)

        view = getMultiAdapter((self.shop.products.product_1,
                                self.shop.products.product_1.REQUEST),
                               name="addToCart")
        view.addToCart()

        items = IItemManagement(cart).getItems()
        self.assertEqual(len(items), 2)

        self.login("newmember")

        cart = ICartManagement(self.shop).getCart()
        items = IItemManagement(cart).getItems()
        self.assertEqual(len(items), 2)
        self.assertEqual(cart.getId(), "newmember")
Ejemplo n.º 2
0
    def afterSetUp(self):
        """
        """
        super(TestCartItemProperties, self).afterSetUp()
        self.login("newmember")
        cm = ICartManagement(self.shop)
        cart = cm.createCart()

        im = IItemManagement(cart)

        properties = (
            {
                "id": "color",
                "selected_option": "Red"
            },  # -10.0
            {
                "id": "material",
                "selected_option": "Wood"
            },  # 0.0
            {
                "id": "quality",
                "selected_option": "High"
            },  # 1500.0
        )

        im.addItem(self.product_1, properties=properties, quantity=3)
        self.item1 = im.getItems()[0]
Ejemplo n.º 3
0
    def testAddProductAsAnonymous(self):
        """
        """
        self.logout()

        view = getMultiAdapter((self.shop.products.product_2,
                                self.shop.products.product_2.REQUEST),
                               name="addToCart")
        view.addToCart()

        cart = ICartManagement(self.shop).getCart()

        items = IItemManagement(cart).getItems()
        self.assertEqual(len(items), 1)

        view.addToCart()

        items = IItemManagement(cart).getItems()
        self.assertEqual(len(items), 1)

        view = getMultiAdapter((self.shop.products.product_1,
                                self.shop.products.product_1.REQUEST),
                               name="addToCart")
        view.addToCart()

        items = IItemManagement(cart).getItems()
        self.assertEqual(len(items), 2)
Ejemplo n.º 4
0
    def testGetItems(self):
        """
        """
        self.order.invokeFactory("OrderItem", "item_1")
        self.order.invokeFactory("OrderItem", "item_2")        
                        
        im = IItemManagement(self.order)
        item_ids = [item.getId() for item in im.getItems()]

        self.assertEqual(item_ids, ["item_1", "item_2"])
Ejemplo n.º 5
0
 def afterSetUp(self):
     """
     """
     super(TestCartTaxes, self).afterSetUp()
     cm = ICartManagement(self.shop)
     self.cart = cm.createCart()
     
     im = IItemManagement(self.cart)
     im.addItem(self.product_1, properties=(), quantity=2)
     im.addItem(self.product_2, properties=(), quantity=3)
Ejemplo n.º 6
0
    def testDeleteItemByOrd(self):
        """
        """
        self.login("newmember")
    
        view = getMultiAdapter((self.shop.products.product_1, self.shop.products.product_1.REQUEST), name="addToCart")
        view.addToCart()

        cart = ICartManagement(self.shop).getCart()    
        im = IItemManagement(cart)            
        im.deleteItemByOrd(0)
    
        self.failIf(hasattr(cart, "0"))
Ejemplo n.º 7
0
    def getOrders(self):
        """
        """
        om = IOrderManagement(IShopManagement(self.context).getShop())
        
        result = []
        for order in om.getOrders():
            
            # omit closed orders
            wftool = getToolByName(self.context, "portal_workflow")
            if wftool.getInfoFor(order, "review_state") == "closed":
                continue
                
            customer = order.getCustomer()

            # am = IAddressManagement(customer)
            # shipping_address = am.getShippingAddress()
            
            im = IItemManagement(order)
            for item in im.getItems():

                product = item.getProduct()
                
                row = (
                    order.getId(),
                    customer.getId(),
                    # shipping_address.getFirstname() + " " + shipping_address.getLastname(),
                    product.getArticle_id(),
                    product.Title(),
                    "%s"   % item.getProductQuantity(),
                    "%.2f" % item.getProductPriceGross(),
                    "%.2f" % item.getProductPriceNet(),
                    "%.2f" % item.getProductTax(),
                    "%.2f" % item.getTax(),
                    "%.2f" % item.getTaxRate(),
                    "%.2f" % item.getPriceGross(),
                    "%.2f" % item.getPriceNet(),
                )
                
                # row = ['"%s"' % field for field in row]
                row = ";".join(row)
                
                result.append(row)

        self.request.response.setHeader('Content-type', 'text/plain')
        self.request.response.setHeader(
            'Content-disposition',
            'attachment; filename=%s' % "orders.csv"
        )

        return "\n".join(result)
Ejemplo n.º 8
0
    def afterSetUp(self):
        """
        """
        super(TestCartItems, self).afterSetUp()

        self.login("newmember")
        cm = ICartManagement(self.shop)
        cart = cm.createCart()

        im = IItemManagement(cart)
        im.addItem(self.product_1, properties=(), quantity=2)
        im.addItem(self.product_2, properties=(), quantity=3)

        self.item1, self.item2 = im.getItems()
Ejemplo n.º 9
0
 def afterSetUp(self):
     """
     """
     super(TestCartItems, self).afterSetUp()
     
     self.login("newmember")
     cm = ICartManagement(self.shop)
     cart = cm.createCart()
     
     im = IItemManagement(cart)
     im.addItem(self.product_1, properties=(), quantity=2)
     im.addItem(self.product_2, properties=(), quantity=3)
     
     self.item1, self.item2 = im.getItems()
Ejemplo n.º 10
0
    def getOrders(self):
        """
        """
        om = IOrderManagement(IShopManagement(self.context).getShop())

        result = []
        for order in om.getOrders():

            # omit closed orders
            wftool = getToolByName(self.context, "portal_workflow")
            if wftool.getInfoFor(order, "review_state") == "closed":
                continue

            customer = order.getCustomer()

            # am = IAddressManagement(customer)
            # shipping_address = am.getShippingAddress()

            im = IItemManagement(order)
            for item in im.getItems():

                product = item.getProduct()

                row = (
                    order.getId(),
                    customer.getId(),
                    # shipping_address.getFirstname() + " " + shipping_address.getLastname(),
                    product.getArticle_id(),
                    product.Title(),
                    "%s" % item.getProductQuantity(),
                    "%.2f" % item.getProductPriceGross(),
                    "%.2f" % item.getProductPriceNet(),
                    "%.2f" % item.getProductTax(),
                    "%.2f" % item.getTax(),
                    "%.2f" % item.getTaxRate(),
                    "%.2f" % item.getPriceGross(),
                    "%.2f" % item.getPriceNet(),
                )

                # row = ['"%s"' % field for field in row]
                row = ";".join(row)

                result.append(row)

        self.request.response.setHeader('Content-type', 'text/plain')
        self.request.response.setHeader(
            'Content-disposition', 'attachment; filename=%s' % "orders.csv")

        return "\n".join(result)
Ejemplo n.º 11
0
    def testDeleteItemByOrd(self):
        """
        """
        self.login("newmember")

        view = getMultiAdapter((self.shop.products.product_1,
                                self.shop.products.product_1.REQUEST),
                               name="addToCart")
        view.addToCart()

        cart = ICartManagement(self.shop).getCart()
        im = IItemManagement(cart)
        im.deleteItemByOrd(0)

        self.failIf(hasattr(cart, "0"))
Ejemplo n.º 12
0
    def isComplete(self):
        """Checks weather the customer is complete to checkout.
        
           Customer completeness means the customer is ready to check out:
             1. Invoice address is complete
             2. Shipping address is complete
             3. Selected payment method is complete
             4. There a items in the cart            
        """
        # Get shop
        shop = self.context.getShop()

        # Get shipping and invoice address
        adressman = IAddressManagement(self.context)

        s_addr = adressman.getShippingAddress()
        if s_addr is None: return False

        i_addr = adressman.getInvoiceAddress()
        if i_addr is None: return False

        # Get payment method
        payman = IPaymentManagement(self.context)
        paymeth = payman.getSelectedPaymentMethod()

        # Get cart of the customer
        cart = ICartManagement(shop).getCart()

        # If there is no cart, the customer hasn't selected a product, hence
        # he is not complete
        if cart is None:
            return False

        im = IItemManagement(cart)

        # Check all for completeness
        # if at least one is False customer is not complete, too.
        for toCheck in s_addr, i_addr, paymeth:
            if ICompleteness(toCheck).isComplete() == False:
                return False

        # check items in cart
        if im.hasItems() == False:
            return False

        return True
Ejemplo n.º 13
0
    def isComplete(self):
        """Checks weather the customer is complete to checkout.
        
           Customer completeness means the customer is ready to check out:
             1. Invoice address is complete
             2. Shipping address is complete
             3. Selected payment method is complete
             4. There a items in the cart            
        """        
        # Get shop
        shop = self.context.getShop()
        
        # Get shipping and invoice address
        adressman = IAddressManagement(self.context)
        
        s_addr = adressman.getShippingAddress()
        if s_addr is None: return False
        
        i_addr = adressman.getInvoiceAddress()
        if i_addr is None: return False

        # Get payment method
        payman = IPaymentManagement(self.context)
        paymeth = payman.getSelectedPaymentMethod()

        # Get cart of the customer
        cart = ICartManagement(shop).getCart()

        # If there is no cart, the customer hasn't selected a product, hence
        # he is not complete
        if cart is None:
            return False
            
        im = IItemManagement(cart)
        
        # Check all for completeness
        # if at least one is False customer is not complete, too.        
        for toCheck in s_addr, i_addr, paymeth:
            if ICompleteness(toCheck).isComplete() == False:
                return False
        
        # check items in cart
        if im.hasItems() == False:
            return False

        return True
Ejemplo n.º 14
0
    def testAddItemFromCartItem(self):
        """
        """
        cm = ICartManagement(self.shop)
        cart = cm.createCart()

        properties = (
            {"id" : "color"   , "selected_option" : "Red" },    # -10.0
            {"id" : "material", "selected_option" : "Wood"},    # 0.0
            {"id" : "quality" , "selected_option" : "High"},    # 1500.0
        )

        cim = IItemManagement(cart)
        cim.addItem(self.product_1, properties=properties, quantity=3)
                
        cart_item = IItemManagement(cart).getItems()[0]
        
        oim = IItemManagement(self.order)        
        oim.addItemFromCartItem("0", cart_item)
        
        order_item = oim.getItems()[0]
        
        self.assertEqual(order_item.getProductQuantity(), 3)
        self.assertEqual(order_item.getProductPriceGross(), 22.0)
        self.assertEqual("%.2f" % order_item.getProductPriceNet(), "18.49")
        self.assertEqual("%.2f" % order_item.getProductTax(), "3.51")
        self.assertEqual(order_item.getPriceGross(), 4536.0)
        self.assertEqual("%.2f" % order_item.getPriceNet(), "3811.76")
        self.assertEqual(order_item.getTaxRate(), 19.0)
        self.assertEqual("%.2f" % order_item.getTax(), "724.24")
        self.assertEqual(order_item.getEasyshopproducts(), self.product_1)
        
        properties = order_item.getProperties()
            
        self.assertEqual(properties[0]["title"], "Color")
        self.assertEqual(properties[0]["selected_option"], "Red")
        self.assertEqual(properties[0]["price"], "-10.0")

        self.assertEqual(properties[1]["title"], "Material")
        self.assertEqual(properties[1]["selected_option"], "Wood")
        self.assertEqual(properties[1]["price"], "0.0")

        self.assertEqual(properties[2]["title"], "Quality")
        self.assertEqual(properties[2]["selected_option"], "High")
        self.assertEqual(properties[2]["price"], "1500.0")
Ejemplo n.º 15
0
    def afterSetUp(self):
        """
        """
        super(TestCartItemProperties, self).afterSetUp()
        self.login("newmember")
        cm = ICartManagement(self.shop)
        cart = cm.createCart()
        
        im = IItemManagement(cart)

        properties = (
            {"id" : "color"   , "selected_option" : "Red" },    # -10.0
            {"id" : "material", "selected_option" : "Wood"},    # 0.0
            {"id" : "quality" , "selected_option" : "High"},    # 1500.0
        )

        im.addItem(self.product_1, properties=properties, quantity=3)
        self.item1 = im.getItems()[0]
Ejemplo n.º 16
0
 def testHasItemsAsAdmin(self):
     """
     """
     cm = ICartManagement(self.shop)
     cart = cm.createCart()
     
     # This caused an error as shasattr was not yet used within
     # CartManagement.getCart(). It returned an ATFolder.
     im = IItemManagement(cart)
Ejemplo n.º 17
0
    def testAddItemsFromCart(self):
        """
        """
        view = getMultiAdapter((self.shop.products.product_1, self.shop.products.product_1.REQUEST), name="addToCart")
        view.addToCart()

        view = getMultiAdapter((self.shop.products.product_2, self.shop.products.product_2.REQUEST), name="addToCart")
        view.addToCart()

        cm = ICartManagement(self.shop)
        cart = cm.getCart()
        
        im = IItemManagement(self.order)
        im.addItemsFromCart(cart)

        product_ids = [item.getProduct().getId() for item in im.getItems()]

        self.assertEqual(product_ids, ["product_1", "product_2"])
Ejemplo n.º 18
0
    def testHasItems(self):
        """
        """
        self.logout()

        cm = ICartManagement(self.shop)
        cart = cm.createCart()
        
        im = IItemManagement(cart)

        self.assertEqual(im.hasItems(), False)
        im.addItem(self.product_1, properties=[])                
        self.assertEqual(im.hasItems(), True)
Ejemplo n.º 19
0
    def testDeleteItem(self):
        """
        """
        self.logout()

        cm = ICartManagement(self.shop)
        cart = cm.createCart()
        
        im = IItemManagement(cart)
        
        im.addItem(self.product_1, properties=())
        self.assertEqual(len(im.getItems()), 1)

        im.addItem(self.product_2, properties=(), quantity=3)
        self.assertEqual(len(im.getItems()), 2)
        
        # Try to delete non existing id
        result = im.deleteItem("3")
        self.assertEqual(result, False)

        # Still 2 items in there
        self.assertEqual(len(im.getItems()), 2)

        # delete first item
        result = im.deleteItem("0")
        self.assertEqual(result, True)        
        self.assertEqual(len(im.getItems()), 1)

        # delete second item
        result = im.deleteItem("1")
        self.assertEqual(result, True)        
        self.assertEqual(len(im.getItems()), 0)
Ejemplo n.º 20
0
    def testAddItemsFromCart(self):        
        """
        """
        cm = ICartManagement(self.shop)
        cart1 = cm.createCart()
        
        im1 = IItemManagement(cart1)
        
        im1.addItem(self.product_1, properties=())
        im1.addItem(self.product_2, properties=(), quantity=3)
        
        self.login("newmember")
        cart2 = cm.createCart()

        im2 = IItemManagement(cart2)
        im2.addItemsFromCart(cart1)
        
        self.assertEqual(len(im2.getItems()), 2)
Ejemplo n.º 21
0
    def testAddItemsAndGetItems(self):
        """
        """
        self.logout()

        cm = ICartManagement(self.shop)
        cart = cm.createCart()
        
        im = IItemManagement(cart)
        
        im.addItem(self.product_1, properties=())
        self.assertEqual(len(im.getItems()), 1)

        im.addItem(self.product_1, properties=())
        self.assertEqual(len(im.getItems()), 1)

        im.addItem(self.product_1, properties=(), quantity=2)
        self.assertEqual(len(im.getItems()), 1)

        im.addItem(self.product_2, properties=(), quantity=3)
        self.assertEqual(len(im.getItems()), 2)

        i1, i2 = im.getItems()        

        i1.getId() == "0"
        i1.getProduct() == self.product_1
        i1.getAmount() == 4
        
        i1.getId() == "1"
        i1.getProduct() == self.product_2
        i1.getAmount() == 2
Ejemplo n.º 22
0
 def testDeleteItem(self):
     """
     """
     im = IItemManagement(self.order)
     self.assertRaises(Exception, im.deleteItem, "dummy_id")
Ejemplo n.º 23
0
 def testDeleteItemByOrd(self):
     """
     """
     im = IItemManagement(self.order)
     self.assertRaises(Exception, im.deleteItemByOrd, 0)
Ejemplo n.º 24
0
 def testAddItem(self):
     """
     """
     im = IItemManagement(self.order)
     self.assertRaises(Exception, im.addItem, "dummy_product")
Ejemplo n.º 25
0
    def testDeleteItemByOrd(self):
        """
        """
        self.logout()

        cm = ICartManagement(self.shop)
        cart = cm.createCart()
        
        im = IItemManagement(cart)
        
        im.addItem(self.product_1, properties=())
        self.assertEqual(len(im.getItems()), 1)

        im.addItem(self.product_2, properties=(), quantity=3)
        self.assertEqual(len(im.getItems()), 2)

        # Try to delete non existing ord
        result = im.deleteItemByOrd(3)
        self.assertEqual(result, False)

        # Still 2 items in there
        self.assertEqual(len(im.getItems()), 2)
        
        # delete first item
        result = im.deleteItemByOrd(0)
        self.assertEqual(result, True)        
        self.assertEqual(len(im.getItems()), 1)

        # Once again, but now it should be another
        result = im.deleteItemByOrd(0)
        self.assertEqual(result, True)        
        self.assertEqual(len(im.getItems()), 0)