Ejemplo n.º 1
0
    def _showSubTree(self, category):
        """Decides, whether a subtree of a category will be displayed or not.
        """
        if self.data.expand_all == True:
            return True

        context_url  = self.context.absolute_url()
        category_url = category.getURL()

        if context_url.startswith(category_url) == True:
            return True  
                  
        elif IProduct.providedBy(self.context) == True:
            cm = ICategoryManagement(self.context)
            try:
                product_category = cm.getTopLevelCategories()[0]
            except IndexError:
                return False
            
            while ICategory.providedBy(product_category) == True:
                if product_category.UID() == category.UID:
                    return True
                product_category = product_category.aq_inner.aq_parent
    
        return False
Ejemplo n.º 2
0
    def _isCurrentItem(self, category):
        """Selected category and parent are current categories.
        """
        context_url = self.context.absolute_url()
        category_url = hasattr(category,'getURL') and category.getURL() or \
            category.absolute_url()

        if context_url.startswith(category_url):
            return True

        elif IProduct.providedBy(self.context):
            try:
                product_category = self.context.getBRefs(
                    "categories_products")[0]
            except IndexError:
                return False

            # UID doesn't work here. Don't know why yet.
            category_url = category.getPath()
            context_url = "/".join(product_category.getPhysicalPath())

            if context_url.startswith(category_url):
                return True

        return False
Ejemplo n.º 3
0
 def available(self):
     """
     """
     if IProduct.providedBy(self.context) and (len(self._data()) > 0):
         return True
     else:
         return False
Ejemplo n.º 4
0
    def _showSubTree(self, category):
        """Decides, whether a subtree of a category will be displayed or not.
        """
        if self.data.expand_all == True:
            return True

        context_url = self.context.absolute_url()
        category_url = category.getURL()

        if context_url.startswith(category_url) == True:
            return True

        elif IProduct.providedBy(self.context) == True:
            cm = ICategoryManagement(self.context)
            try:
                product_category = cm.getTopLevelCategories()[0]
            except IndexError:
                return False

            while ICategory.providedBy(product_category) == True:
                if product_category.UID() == category.UID:
                    return True
                product_category = product_category.aq_inner.aq_parent

        return False
Ejemplo n.º 5
0
 def available(self):
     """
     """
     if IProduct.providedBy(self.context) and (len(self._data()) > 0):
         return True
     else:
         return False
Ejemplo n.º 6
0
    def showGlobalProperties(self):
        """Returns True for product content objects. False for groups.

        This view is used for groups and products, so the global properties 
        section (properties which come from groups) have to be hidden for 
        groups.
        """
        if IProduct.providedBy(self.context):
            return True
        else:
            return False
Ejemplo n.º 7
0
    def showGlobalProperties(self):
        """Returns True for product content objects. False for groups.

        This view is used for groups and products, so the global properties 
        section (properties which come from groups) have to be hidden for 
        groups.
        """
        if IProduct.providedBy(self.context):
            return True
        else:
            return False        
Ejemplo n.º 8
0
def categories(object, portal, **kwargs):
    """Indexes all categories and parent categories of a product.
    """
    try:
        result = {}
        if IProduct.providedBy(object):
            for category in ICategoryManagement(object).getTopLevelCategories():
                result[category.UID()] = 1
                
                # Collect parent categories
                object = category
                while object is not None:
                    result[object.UID()] = 1
                    object = object.getParentCategory()
            
        return result.keys()
        
    except (ComponentLookupError, TypeError, ValueError):
        raise AttributeError
Ejemplo n.º 9
0
    def _showSubTree(self, category):
        """Decides, whether a subtree of a category will be displayed or not.
        """
        if self.data.expand_all == True:
            return True
        
        # Check if the passed category is ancestor of context
        if ICategory.providedBy(self.context) == True:
            obj = self.context
            while obj is not None:
                if category == obj:
                    return True
                try:
                    obj = obj.getRefs("parent_category")[0]
                except IndexError:
                    obj = None
                    

        if IProduct.providedBy(self.context) == True:
            cm = ICategoryManagement(self.context)
            try:
                product_category = cm.getTopLevelCategories()[0]
            except IndexError:
                return False
            
            while ICategory.providedBy(product_category) == True:
                if product_category.UID() == category.UID():
                    return True
                product_category = product_category.aq_inner.aq_parent
    
            return False
        
        if IProductSelector.providedBy(self.context) == True:
            obj = self.context.aq_inner.aq_parent
            while obj is not None:
                if category == obj:
                    return True
                try:
                    obj = obj.getRefs("parent_category")[0]
                except IndexError:
                    obj = None

        return False
Ejemplo n.º 10
0
    def _showSubTree(self, category):
        """Decides, whether a subtree of a category will be displayed or not.
        """
        if self.data.expand_all == True:
            return True

        # Check if the passed category is ancestor of context
        if ICategory.providedBy(self.context) == True:
            obj = self.context
            while obj is not None:
                if category == obj:
                    return True
                try:
                    obj = obj.getRefs("parent_category")[0]
                except IndexError:
                    obj = None

        if IProduct.providedBy(self.context) == True:
            cm = ICategoryManagement(self.context)
            try:
                product_category = cm.getTopLevelCategories()[0]
            except IndexError:
                return False

            while ICategory.providedBy(product_category) == True:
                if product_category.UID() == category.UID():
                    return True
                product_category = product_category.aq_inner.aq_parent

            return False

        if IProductSelector.providedBy(self.context) == True:
            obj = self.context.aq_inner.aq_parent
            while obj is not None:
                if category == obj:
                    return True
                try:
                    obj = obj.getRefs("parent_category")[0]
                except IndexError:
                    obj = None

        return False
Ejemplo n.º 11
0
def categories(object, portal, **kwargs):
    """Indexes all categories and parent categories of a product.
    """
    try:
        result = {}
        if IProduct.providedBy(object):
            for category in ICategoryManagement(
                    object).getTopLevelCategories():
                result[category.UID()] = 1

                # Collect parent categories
                object = category
                while object is not None:
                    result[object.UID()] = 1
                    object = object.getParentCategory()

        return result.keys()

    except (ComponentLookupError, TypeError, ValueError):
        raise AttributeError
Ejemplo n.º 12
0
 def _isCurrentItem(self, category):
     """Selected category and parent are current categories.
     """
     context_url  = self.context.absolute_url()
     category_url = category.getURL()
     
     if context_url.startswith(category_url):
         return True
         
     elif IProduct.providedBy(self.context):
         try:
             product_category = self.context.getBRefs("mall_categories_products")[0]
         except IndexError:
             return False
     
         # UID doesn't work here. Don't know why yet.
         category_url = category.getPath()
         context_url  = "/".join(product_category.getPhysicalPath())
         
         if context_url.startswith(category_url):
             return True
         
     return False
Ejemplo n.º 13
0
    def getContent(self):
        """
        """
        data = {}

        # Title
        if self.context.getOverwriteTitle() == True:
            title = self.context.Title()
        else:
            title = self.object.Title()

        # Text
        if self.context.getOverwriteText() == True:
            text = self.context.getText()
        else:
            text = self.object.getText()

        # Image
        if len(self.context.getImage()) != 0:
            image = self.context
        else:
            image = IImageManagement(self.object).getMainImage()

        if image is not None:
            image_url = image.absolute_url()
        else:
            image_url = None

        # Price
        if IProduct.providedBy(self.object) == True:
            cm = ICurrencyManagement(self.object)
            p = IPrices(self.object)

            # Effective price
            price = p.getPriceForCustomer()
            price = cm.priceToString(price, symbol="symbol", position="before")

            # Standard price
            standard_price = p.getPriceForCustomer(effective=False)
            standard_price = cm.priceToString(standard_price,
                                              symbol="symbol",
                                              position="before")

            for_sale = self.object.getForSale()

        else:
            for_sale = False
            standard_price = "0.0"
            price = "0.0"

        data.update({
            "portal_type": self.object.getPortalTypeName(),
            "id": self.object.getId(),
            "url": self.object.absolute_url(),
            "title": title,
            "description": self.object.Description(),
            "text": text,
            "image_url": image_url,
            "price": price,
            "standard_price": standard_price,
            "for_sale": for_sale,
            "image_size": self.context.getImageSize(),
        })

        return data
Ejemplo n.º 14
0
    def getContent(self):
        """
        """
        data = {}

        # Title
        if self.context.getOverwriteTitle() == True:
            title = self.context.Title()
        else:
            title = self.object.Title()

        # Text
        if self.context.getOverwriteText() == True:
            text = self.context.getText()
        else:
            text = self.object.getText()

        # Image    
        if len(self.context.getImage()) != 0:
            image = self.context            
        else:
            image = IImageManagement(self.object).getMainImage()
        
        if image is not None:
            image_url = image.absolute_url()
        else:
            image_url = None

        # Price
        if IProduct.providedBy(self.object) == True:
            cm = ICurrencyManagement(self.object)            
            p = IPrices(self.object)

            # Effective price
            price = p.getPriceForCustomer()
            price = cm.priceToString(price, symbol="symbol", position="before")
        
            # Standard price
            standard_price = p.getPriceForCustomer(effective=False)
            standard_price = cm.priceToString(
                standard_price, symbol="symbol", position="before")
            
            for_sale = self.object.getForSale()
            
        else:
            for_sale = False
            standard_price = "0.0"
            price = "0.0"
            
        data.update({
            "portal_type"    : self.object.getPortalTypeName(),
            "id"             : self.object.getId(),
            "url"            : self.object.absolute_url(),
            "title"          : title,
            "description"    : self.object.Description(),
            "text"           : text,
            "image_url"      : image_url,
            "price"          : price,
            "standard_price" : standard_price,
            "for_sale"       : for_sale,
            "image_size"     : self.context.getImageSize(),
        })

        return data
Ejemplo n.º 15
0
 def available(self):
     """
     """
     return IProduct.providedBy(self.context)
Ejemplo n.º 16
0
 def available(self):
     """
     """
     return IProduct.providedBy(self.context)