Ejemplo n.º 1
0
    def _getBatch(self):
        """
        """
        # Calculate products per page
        fi = self.getFormatInfo()
        products_per_page = fi.get("lines_per_page") * \
                            fi.get("products_per_line")        

        # Get all products                    
        mtool = getToolByName(self.context, "portal_membership")        
        sorting = self.request.SESSION.get("sorting")
        try:
            sorted_on, sort_order = sorting.split("-")
        except (AttributeError, ValueError):
            sorted_on  = "price"
            sort_order = "desc"
        
        pm = IProductManagement(self.context)
        products = pm.getAllProducts(sorted_on=sorted_on,
                                     sort_order = sort_order)
        
        # Get start page
        b_start  = self.request.get('b_start', 0);

        # Calculate Batch
        return Batch(products, products_per_page, int(b_start), orphan=0);
Ejemplo n.º 2
0
    def getProducts(self):
        """
        """
        shop = IShopManagement(self.context).getShop()
        pm = IProductManagement(shop)
        
        result = []
        for product in pm.getProducts():
            result.append({
                "uid"   : product.UID,
                "title" : product.Title,                
            })
        
        # Get start page                             
        b_start  = self.request.get('b_start', 0);
        if b_start == "None":
            b_start = 0

        batch = Batch(result, 20, int(b_start), orphan=0)
        
        # Calculate Batch
        return {
            "batch"        : batch,
            "next_url"     : self._getNextUrl(batch),
            "previous_url" : self._getPreviousUrl(batch)
        }
Ejemplo n.º 3
0
    def getProducts(self):
        """
        """
        shop = IShopManagement(self.context).getShop()
        pm = IProductManagement(shop)

        result = []
        for product in pm.getProducts():
            result.append({
                "uid": product.UID,
                "title": product.Title,
            })

        # Get start page
        b_start = self.request.get('b_start', 0)
        if b_start == "None":
            b_start = 0

        batch = Batch(result, 20, int(b_start), orphan=0)

        # Calculate Batch
        return {
            "batch": batch,
            "next_url": self._getNextUrl(batch),
            "previous_url": self._getPreviousUrl(batch)
        }
    def testGetAmountOfProducts_1(self):
        """As manager
        """
        pm = IProductManagement(self.shop.groups.group_1)
        self.assertEqual(len(pm.getProducts()), 2)

        pm = IProductManagement(self.shop.groups.group_2)
        self.assertEqual(len(pm.getProducts()), 1)
Ejemplo n.º 5
0
    def testGetAllProducts(self):
        """
        """
        pm = IProductManagement(self.portal.myshop.categories.category_1)
        product_ids = [p.getId() for p in pm.getAllProducts()]
        self.assertEqual(product_ids, ["product_1", "product_2"])

        pm = IProductManagement(self.portal.myshop.categories.category_1.category_11)
        product_ids = [p.getId() for p in pm.getAllProducts()]
        self.assertEqual(product_ids, ["product_1", "product_2"])
    def testGetAmountOfProducts_2(self):
        """As anonymous. Note that only products are counted for which the user
        has the View permission.
        """
        self.logout()
        pm = IProductManagement(self.shop.groups.group_1)
        self.assertEqual(len(pm.getProducts()), 0)

        pm = IProductManagement(self.shop.groups.group_2)
        self.assertEqual(len(pm.getProducts()), 0)
    def testGetProducts_1(self):
        """As manager
        """
        pm = IProductManagement(self.shop.groups.group_1)
        product_ids = [p.getId() for p in pm.getProducts()]        
        self.assertEqual(product_ids, ["product_1", "product_2"])

        pm = IProductManagement(self.shop.groups.group_2)
        product_ids = [p.getId() for p in pm.getProducts()]        
        self.assertEqual(product_ids, ["product_1"])
    def testGetAmountOfProducts_3(self):
        """As anonymous, with product_2 published.
        """
        wftool = getToolByName(self.shop, "portal_workflow")
        wftool.doActionFor(self.product_2, "publish")
        
        self.logout()

        pm = IProductManagement(self.shop.groups.group_1)
        self.assertEqual(len(pm.getProducts()), 1)

        pm = IProductManagement(self.shop.groups.group_2)
        self.assertEqual(len(pm.getProducts()), 0)
    def testGetProducts_2(self):
        """As anonymous. Note hat only products return for which the user has
        the View permission.
        """
        self.logout()
        
        pm = IProductManagement(self.shop.groups.group_1)
        product_ids = [p.getId() for p in pm.getProducts()]
        self.assertEqual(product_ids, [])

        pm = IProductManagement(self.shop.groups.group_2)
        product_ids = [p.getId() for p in pm.getProducts()]        
        self.assertEqual(product_ids, [])
Ejemplo n.º 10
0
    def getProductURLs(self):
        """
        """
        sorting = self.request.SESSION.get("sorting")
        try:
            sorted_on, sort_order = sorting.split("-")
        except (AttributeError, ValueError):
            sorted_on  = "price"
            sort_order = "desc"
        
        # all categories of the product
        cm = ICategoryManagement(self.context)
        categories = cm.getTopLevelCategories()
        
        result = []
        for category in categories:
            pm = IProductManagement(category)
            products = pm.getAllProducts(
                sorted_on=sorted_on,
                sort_order = sort_order)
            
            # determine position of product within category
            index = products.index(self.context)
            
            # generate previous/next url
            temp = {}            
            if index==0:
                temp["previous"] = None
                temp["first"] = None
            else:
                product = products[index-1]
                temp["previous"] = product.absolute_url()
                temp["first"] = products[0].absolute_url()
            try:
                product = products[index+1]
                temp["next"] = product.absolute_url()
                temp["last"] = products[-1].absolute_url()
            except IndexError:
                temp["next"] = None
                temp["last"] = None

            temp["category_url"] = category.absolute_url()
            temp["category"] = category.Title()
            temp["position"] = index + 1
            temp["amount"] = len(products)            
            
            result.append(temp)
            
        return result
Ejemplo n.º 11
0
    def getProductURLs(self):
        """
        """
        sorting = self.request.SESSION.get("sorting")
        try:
            sorted_on, sort_order = sorting.split("-")
        except (AttributeError, ValueError):
            sorted_on = "price"
            sort_order = "desc"

        # all categories of the product
        cm = ICategoryManagement(self.context)
        categories = cm.getTopLevelCategories()

        result = []
        for category in categories:
            pm = IProductManagement(category)
            products = pm.getAllProducts(sorted_on=sorted_on,
                                         sort_order=sort_order)

            # determine position of product within category
            index = products.index(self.context)

            # generate previous/next url
            temp = {}
            if index == 0:
                temp["previous"] = None
                temp["first"] = None
            else:
                product = products[index - 1]
                temp["previous"] = product.absolute_url()
                temp["first"] = products[0].absolute_url()
            try:
                product = products[index + 1]
                temp["next"] = product.absolute_url()
                temp["last"] = products[-1].absolute_url()
            except IndexError:
                temp["next"] = None
                temp["last"] = None

            temp["category_url"] = category.absolute_url()
            temp["category"] = category.Title()
            temp["position"] = index + 1
            temp["amount"] = len(products)

            result.append(temp)

        return result
Ejemplo n.º 12
0
    def testGetTotalAmountOfProducts(self):
        """
        """
        pm = IProductManagement(self.portal.myshop.categories.category_1)
        self.assertEqual(pm.getTotalAmountOfProducts(), 2)

        pm = IProductManagement(self.portal.myshop.categories.category_2)
        self.assertEqual(pm.getTotalAmountOfProducts(), 0)

        pm = IProductManagement(
            self.portal.myshop.categories.category_1.category_11)
        self.assertEqual(pm.getTotalAmountOfProducts(), 2)
Ejemplo n.º 13
0
    def testGetProducts(self):
        """
        """
        pm = IProductManagement(self.portal.myshop.categories.category_1)
        self.assertEqual(pm.getProducts(), [])

        pm = IProductManagement(self.portal.myshop.categories.category_2)
        self.assertEqual(pm.getProducts(), [])

        pm = IProductManagement(
            self.portal.myshop.categories.category_1.category_11)
        product_ids = [p.getId() for p in pm.getProducts()]
        self.assertEqual(product_ids, ["product_1", "product_2"])
Ejemplo n.º 14
0
    def getAllProducts(self, sorted_on=None, sort_order=None):
        """
        """
        pm = IProductManagement(self.context)
        products = pm.getProducts()

        cm = ICategoryManagement(self.context)
        for category in cm.getCategories():
            pm = IProductManagement(category)
            products.extend(pm.getProducts())
            
        if sorted_on == "name":
            products = self._sortProductsByName(products, sort_order)
        elif sorted_on == "price":
            products = self._sortProductsByPrice(products, sort_order)                        

        return products
Ejemplo n.º 15
0
    def testGetProducts_3(self):
        """As anonymous, with product_2 published.
        """
        wftool = getToolByName(self.shop, "portal_workflow")
        wftool.doActionFor(self.product_2, "publish")
        
        self.logout()
        
        pm = IProductManagement(self.shop.groups.group_1)
        product_ids = [p.getId() for p in pm.getProducts()]        
        
        for id in ["product_1", "product_2"]:
            self.failUnless(id not in product_ids)

        pm = IProductManagement(self.shop.groups.group_2)
        product_ids = [p.getId() for p in pm.getProducts()]        
        self.assertEqual(product_ids, [])
Ejemplo n.º 16
0
    def _getProducts(self, category):
        """
        """
        object = category.getObject()

        products = []
        for product in IProductManagement(object).getProducts():
            products.append({
                "title": product.Title(),
                "url": product.absolute_url()
            })

        return products
Ejemplo n.º 17
0
    def testGetAmountOfProducts_1(self):
        """As manager
        """
        pm = IProductManagement(self.shop.groups.group_1)
        self.assertEqual(len(pm.getProducts()), 2)

        pm = IProductManagement(self.shop.groups.group_2)
        self.assertEqual(len(pm.getProducts()), 1)
Ejemplo n.º 18
0
 def showNoProducts(self):
     """
     """
     # If there was a search then return False
     if (self.request.get("letter", None) is not None or \
         self.request.get("searchable_text", None) is not None):
         return False
         
     shop = IShopManagement(self.context).getShop()
     products = IProductManagement(shop).getProducts()
     if len(products) > 0:
         return False
     else:
         return True
Ejemplo n.º 19
0
    def testGetAmountOfProducts_2(self):
        """As anonymous. Note that only products are counted for which the user
        has the View permission.
        """
        self.logout()
        pm = IProductManagement(self.shop.groups.group_1)
        self.assertEqual(len(pm.getProducts()), 0)

        pm = IProductManagement(self.shop.groups.group_2)
        self.assertEqual(len(pm.getProducts()), 0)
Ejemplo n.º 20
0
    def testGetProducts_1(self):
        """As manager
        """
        pm = IProductManagement(self.shop.groups.group_1)
        product_ids = [p.getId() for p in pm.getProducts()]
        self.assertEqual(product_ids, ["product_1", "product_2"])

        pm = IProductManagement(self.shop.groups.group_2)
        product_ids = [p.getId() for p in pm.getProducts()]
        self.assertEqual(product_ids, ["product_1"])
Ejemplo n.º 21
0
    def testGetTotalAmountOfProducts(self):
        """
        """
        pm = IProductManagement(self.portal.myshop.categories.category_1)
        self.assertEqual(pm.getTotalAmountOfProducts(), 2)

        pm = IProductManagement(self.portal.myshop.categories.category_2)
        self.assertEqual(pm.getTotalAmountOfProducts(), 0)

        pm = IProductManagement(self.portal.myshop.categories.category_1.category_11)
        self.assertEqual(pm.getTotalAmountOfProducts(), 2)
Ejemplo n.º 22
0
    def setPrices(self):
        """
        """
        from easyshop.core.interfaces import IProductManagement

        base_category = self.context.kategorien["gartenhauser"]

        for category in base_category.values():

            if category.id == "zubehor":
                continue

            for product in IProductManagement(category).getProducts():
                print product
                price = product.getPrice()
                new_price = "%.2f" % (price * 0.95)
                product.setSalePrice(new_price)
                product.setForSale(True)
Ejemplo n.º 23
0
    def testGetProducts_2(self):
        """As anonymous. Note hat only products return for which the user has
        the View permission.
        """
        self.logout()

        pm = IProductManagement(self.shop.groups.group_1)
        product_ids = [p.getId() for p in pm.getProducts()]
        self.assertEqual(product_ids, [])

        pm = IProductManagement(self.shop.groups.group_2)
        product_ids = [p.getId() for p in pm.getProducts()]
        self.assertEqual(product_ids, [])
Ejemplo n.º 24
0
    def testGetAmountOfProducts_3(self):
        """As anonymous, with product_2 published.
        """
        wftool = getToolByName(self.shop, "portal_workflow")
        wftool.doActionFor(self.product_2, "publish")

        self.logout()

        pm = IProductManagement(self.shop.groups.group_1)
        self.assertEqual(len(pm.getProducts()), 1)

        pm = IProductManagement(self.shop.groups.group_2)
        self.assertEqual(len(pm.getProducts()), 0)
Ejemplo n.º 25
0
    def getAllProducts(self, sorted_on=None, sort_order=None):
        """
        """
        pm = IProductManagement(self.context)
        products = pm.getProducts()

        cm = ICategoryManagement(self.context)
        for category in cm.getCategories():
            pm = IProductManagement(category)
            products.extend(pm.getProducts())

        if sorted_on == "name":
            products = self._sortProductsByName(products, sort_order)
        elif sorted_on == "price":
            products = self._sortProductsByPrice(products, sort_order)

        return products
Ejemplo n.º 26
0
    def testGetProducts_3(self):
        """As anonymous, with product_2 published.
        """
        wftool = getToolByName(self.shop, "portal_workflow")
        wftool.doActionFor(self.product_2, "publish")

        self.logout()

        pm = IProductManagement(self.shop.groups.group_1)
        product_ids = [p.getId() for p in pm.getProducts()]

        for id in ["product_1", "product_2"]:
            self.failUnless(id not in product_ids)

        pm = IProductManagement(self.shop.groups.group_2)
        product_ids = [p.getId() for p in pm.getProducts()]
        self.assertEqual(product_ids, [])
Ejemplo n.º 27
0
    def getProducts(self):
        """
        """
        category_uid = self.request.get("category_uid")
        if category_uid is None:
            return []

        catalog = getToolByName(self.context, "portal_catalog")
        brains = catalog.searchResults(UID=category_uid, )

        try:
            category = brains[0].getObject()
        except IndexError:
            return []

        line = []
        products = []
        for i, product in enumerate(
                IProductManagement(category).getAllProducts()):
            line.append({
                "title": product.Title(),
                "url": product.absolute_url(),
            })

            if (i + 1) % 5 == 0:
                products.append(line)
                line = []

        if len(line) > 0:
            products.append(line)

        return {
            "category_title": category.Title(),
            "category_description": category.Description(),
            "products": products,
        }
Ejemplo n.º 28
0
 def testGetTotalAmountOfProducts(self):
     """
     """
     pm = IProductManagement(self.shop)
     self.assertRaises(Exception, pm.getTotalAmountOfProducts)
Ejemplo n.º 29
0
 def testGetProducts(self):
     """
     """
     pm = IProductManagement(self.shop)
     self.failIf(pm.getProducts() == 0)
Ejemplo n.º 30
0
 def testGetProducts(self):
     """
     """
     pm = IProductManagement(self.shop)
     self.failIf(pm.getProducts() == 0)