Ejemplo n.º 1
0
 def __init__(self, context):
     permissions = [MANAGE_DISCOUNT_PERMISSION]
     super(ShopPortletCartItemDiscountLink, self).__init__(context, view_permissions=permissions)
     if self.display:
         self.display = ISite.providedBy(context) or IDiscountSettingsEnabled.providedBy(context)
     self.url = "%s/@@item_discount" % context.absolute_url()
     self.title = _("item_discount", default=u"Item Discount")
     self.order = 70
     self.cssclass = "item_discount"
Ejemplo n.º 2
0
 def __init__(self, context, request):
     # acquire desired context
     interfaces = [IBuyable, IFolder, ISite]
     context = self.acquire_context(context, interfaces=interfaces)
     # call super class constructor
     super(CartItemDiscountLink, self).__init__(context, request)
     # check whether context is site or discount settings are enabled on
     # context
     if self.display:
         self.display = ISite.providedBy(context) \
             or IDiscountSettingsEnabled.providedBy(context)
     # set target URL
     self.url = '{}/@@item_discount'.format(context.absolute_url())
Ejemplo n.º 3
0
 def __init__(self, context, request):
     # acquire desired context
     interfaces = [IBuyable, IFolder, ISite]
     context = self.acquire_context(context, interfaces=interfaces)
     # call super class constructor
     super(CartItemDiscountLink, self).__init__(context, request)
     # check whether context is site or discount settings are enabled on
     # context
     if self.display:
         self.display = ISite.providedBy(
             context) or IDiscountSettingsEnabled.providedBy(context)
     # set target URL
     self.url = "{}/@@item_discount".format(context.absolute_url())
Ejemplo n.º 4
0
    def rules(self, portal_type=None):
        """Return rules to apply, most outer first.

        Aggregate rules through hierarchy until Plone root is reached.

        Container objects get ignored if ``IDiscountSettingsEnabled`` not
        provided.

        For each context only the first found rule from lookup chain is
        considered.

        Stops hierarchical lookup if found rule for context sets it's ``block``
        flag.
        """
        rules = list()
        context = self.context
        # traverse down at most until plone root
        while True:
            # ignore context if no discount settings enabled or no site
            if not (
                IDiscountSettingsEnabled.providedBy(context)
                or ISite.providedBy(context)
            ):
                context = aq_parent(aq_inner(context))
                continue
            rule = None
            # iterate lookup chain, break on first rule found
            for lookup in self.lookup_chain(context):
                rule = lookup.lookup(portal_type=portal_type)
                if rule:
                    break
            # add rule if found
            if rule:
                rules.append(rule)
                # break aggregating if defined
                if rule.attrs["block"]:
                    break
            # plone root reached
            if IPloneSiteRoot.providedBy(context):
                break
            context = aq_parent(aq_inner(context))
        # aggregated rules are applied most outer first
        return reversed(rules)
Ejemplo n.º 5
0
    def rules(self, portal_type=None):
        """Return rules to apply, most outer first.

        Aggregate rules through hierarchy until Plone root is reached.

        Container objects get ignored if ``IDiscountSettingsEnabled`` not
        provided.

        For each context only the first found rule from lookup chain is
        considered.

        Stops hierarchical lookup if found rule for context sets it's ``block``
        flag.
        """
        rules = list()
        context = self.context
        # traverse down at most until plone root
        while True:
            # ignore context if no discount settings enabled or no site
            if not (IDiscountSettingsEnabled.providedBy(context)
                    or ISite.providedBy(context)):
                context = aq_parent(aq_inner(context))
                continue
            rule = None
            # iterate lookup chain, break on first rule found
            for lookup in self.lookup_chain(context):
                rule = lookup.lookup(portal_type=portal_type)
                if rule:
                    break
            # add rule if found
            if rule:
                rules.append(rule)
                # break aggregating if defined
                if rule.attrs['block']:
                    break
            # plone root reached
            if IPloneSiteRoot.providedBy(context):
                break
            context = aq_parent(aq_inner(context))
        # aggregated rules are applied most outer first
        return reversed(rules)
Ejemplo n.º 6
0
 def rules(self):
     # return rules to apply, most outer first
     rules = list()
     context = self.context
     while True:
         if not (IDiscountSettingsEnabled.providedBy(context)
                 or ISite.providedBy(context)):
             context = aq_parent(aq_inner(context))
             continue
         rule = None
         for lookup in self.lookup_cascade(context):
             rule = lookup.lookup()
             if rule:
                 break
         if rule:
             rules.append(rule)
             if rule.attrs['block']:
                 break
         if IPloneSiteRoot.providedBy(context):
             break
         context = aq_parent(aq_inner(context))
     return reversed(rules)
Ejemplo n.º 7
0
 def can_enable_discount(self):
     return not ISite.providedBy(
         self.context
     ) and not IDiscountSettingsEnabled.providedBy(self.context)
Ejemplo n.º 8
0
 def can_enable_discount(self):
     return not ISite.providedBy(self.context) \
         and not IDiscountSettingsEnabled.providedBy(self.context)