Exemple #1
0
    def getShop(self):
        """
        """
        object = self.context
        try:
            while IShop.providedBy(object) == False:
                if object.meta_type == "Plone Factory Tool":
                    object = object.aq_parent
                else:
                    object = object.aq_inner.aq_parent
        except AttributeError:

            # Next line is needed for the temporary products for payment and
            # shipping. As they have real context above code seems not to
            # work. But they have given the shop as context so we can give
            # it back here. See also:
            # - adapters/shop/payment/createTemporaryPaymentProduct
            # - adapters/shop/shipping/createTemporaryShippingProduct.            
            # I'm not sure whether this is clean, I assume it is not.
            
            try:
                if IShop.providedBy(object.context):
                    return object.context            
                else:
                    return None
            except AttributeError:
                return None
                
        return object
Exemple #2
0
    def getShop(self):
        """
        """
        object = self.context
        try:
            while IShop.providedBy(object) == False:
                if object.meta_type == "Plone Factory Tool":
                    object = object.aq_parent
                else:
                    object = object.aq_inner.aq_parent
        except AttributeError:

            # Next line is needed for the temporary products for payment and
            # shipping. As they have real context above code seems not to
            # work. But they have given the shop as context so we can give
            # it back here. See also:
            # - adapters/shop/payment/createTemporaryPaymentProduct
            # - adapters/shop/shipping/createTemporaryShippingProduct.
            # I'm not sure whether this is clean, I assume it is not.

            try:
                if IShop.providedBy(object.context):
                    return object.context
                else:
                    return None
            except AttributeError:
                return None

        return object
Exemple #3
0
 def showEnabledField(self):
     """Returns True when the enabled field should be displayed.
     """
     if IShop.providedBy(self.context) == True:
         return False
     else:
         return True
Exemple #4
0
 def showEnabledField(self):
     """Returns True when the enabled field should be displayed.
     """
     if IShop.providedBy(self.context) == True:
         return False
     else:
         return True
Exemple #5
0
    def getBackToOverViewUrl(self):
        """
        """
        if IShop.providedBy(self.context):
            return None

        parent_category = self.context.getRefs("parent_category")
        if len(parent_category) > 0:
            return parent_category[0].absolute_url()

        shop = IShopManagement(self.context).getShop()
        return shop.absolute_url()
Exemple #6
0
    def getBackToOverViewUrl(self):
        """
        """
        if IShop.providedBy(self.context):
            return None
        
        parent_category = self.context.getRefs("parent_category")
        if len(parent_category) > 0:
            return parent_category[0].absolute_url()

        shop = IShopManagement(self.context).getShop()
        return shop.absolute_url()
Exemple #7
0
    def getFormats(self, effective=True):
        """Returns either the first object with formats enabled or the shop
        content object
        """
        object = self.context
        if effective == True:
            while IShop.providedBy(object) == False:
                try:
                    fi = IFormats(object)
                except TypeError:
                    pass
                else:
                    if fi.formats["enabled"] == True:
                        break

                if base_hasattr(object, "getParentCategory") and \
                   object.getParentCategory() is not None:
                    object = object.getParentCategory()
                else:
                    object = object.aq_inner.aq_parent

        fi = IFormats(object)

        try:
            lines_per_page = int(fi.formats["lines_per_page"])
        except (TypeError, ValueError):
            lines_per_page = 1

        try:
            products_per_line = int(fi.formats["products_per_line"])
        except (TypeError, ValueError):
            products_per_line = 2

        try:
            product_height = int(fi.formats["product_height"])
        except (TypeError, ValueError):
            product_height = 0

        return {
            "enabled": fi.formats["enabled"],
            "lines_per_page": lines_per_page,
            "products_per_line": products_per_line,
            "product_height": product_height,
            "image_size": fi.formats["image_size"],
            "text": fi.formats["text"],
            "title": fi.formats["title"],
            "chars": fi.formats["chars"],
        }
Exemple #8
0
    def getFormats(self, effective=True):
        """Returns either the first object with formats enabled or the shop
        content object
        """
        object = self.context
        if effective == True:
            while IShop.providedBy(object) == False:
                try:                 
                    fi = IFormats(object)
                except TypeError:
                    pass
                else:              
                    if fi.formats["enabled"] == True:
                        break
                                
                if base_hasattr(object, "getParentCategory") and \
                   object.getParentCategory() is not None:
                    object = object.getParentCategory()
                else:
                    object = object.aq_inner.aq_parent
        
        fi = IFormats(object)
        
        try:
            lines_per_page = int(fi.formats["lines_per_page"])
        except (TypeError, ValueError):
            lines_per_page = 1

        try:
            products_per_line = int(fi.formats["products_per_line"])
        except (TypeError, ValueError):
            products_per_line = 2

        try:
            product_height = int(fi.formats["product_height"])
        except (TypeError, ValueError):
            product_height = 0
            
        return {
            "enabled"           : fi.formats["enabled"],
            "lines_per_page"    : lines_per_page,
            "products_per_line" : products_per_line,
            "product_height"    : product_height,
            "image_size"        : fi.formats["image_size"],
            "text"              : fi.formats["text"],            
            "title"             : fi.formats["title"],
            "chars"             : fi.formats["chars"],
        }
Exemple #9
0
    def getProducts(self, category_id=None):
        """
        """
        shop_or_mall = IShopManagement(self.context).getShop()

        # NOTE: The more specific one has to be the first, because a mall is
        # also a shop
        if IMall.providedBy(shop_or_mall):
            reference = "mall_categories_products"
        elif IShop.providedBy(shop_or_mall):
            reference = "categories_products"
        else:
            return []

        mtool = getToolByName(self.context, "portal_membership")

        result = []
        # Returns just "View"-able products.
        for product in self.context.getRefs(reference):
            if mtool.checkPermission("View", product) is not None:
                result.append(product)

        return result
Exemple #10
0
    def getProducts(self, category_id=None):
        """
        """
        shop_or_mall = IShopManagement(self.context).getShop()

        # NOTE: The more specific one has to be the first, because a mall is
        # also a shop
        if IMall.providedBy(shop_or_mall):
            reference = "mall_categories_products"
        elif IShop.providedBy(shop_or_mall):
            reference = "categories_products"
        else:
            return []

        mtool = getToolByName(self.context, "portal_membership")

        result = []
        # Returns just "View"-able products.
        for product in self.context.getRefs(reference):
            if mtool.checkPermission("View", product) is not None:
                result.append(product)

        return result