Ejemplo n.º 1
0
 def aggregated_count(self):
     items = extractitems(readcookie(self.request))
     stock_data = ISharedStockData(self.context)
     aggregated_count = 0
     for uid in stock_data.related_uids:
         aggregated_count += aggregate_cart_item_count(uid, items)
     return aggregated_count
Ejemplo n.º 2
0
 def aggregated_count(self):
     items = extractitems(readcookie(self.request))
     stock_data = ISharedStockData(self.context)
     aggregated_count = 0
     for uid in stock_data.related_uids:
         aggregated_count += aggregate_cart_item_count(uid, items)
     return aggregated_count
Ejemplo n.º 3
0
 def cart_total_count(self):
     # XXX: how to handle float?
     # XXX: count total items in cart or total unique items in cart?
     ret = Decimal('0')
     for uid, count, comment in extractitems(readcookie(self.request)):
         ret += count
     return ret
Ejemplo n.º 4
0
 def cart_total_count(self):
     # XXX: how to handle float?
     # XXX: count total items in cart or total unique items in cart?
     ret = Decimal('0')
     for uid, count, comment in extractitems(readcookie(self.request)):
         ret += count
     return ret
Ejemplo n.º 5
0
    def test_extractitems_has_items(self):
        from bda.plone.cart import extractitems

        items = "uid-1:5,uid-2:100,uid-3:7"
        self.assertEquals(
            extractitems(items),
            [("uid-1", 5, ""), ("uid-2", 100, ""), ("uid-3", 7, "")],
        )
Ejemplo n.º 6
0
    def test_extractitems_has_items(self):
        from bda.plone.cart import extractitems

        items = 'uid-1:5,uid-2:100,uid-3:7'
        self.assertEquals(
            extractitems(items),
            [('uid-1', 5, '', ), ('uid-2', 100, '', ), ('uid-3', 7, '', )]
        )
Ejemplo n.º 7
0
    def test_extractitems_has_items(self):
        from bda.plone.cart import extractitems

        items = 'uid-1:5,uid-2:100,uid-3:7'
        self.assertEquals(
            extractitems(items),
            [('uid-1', 5, '', ), ('uid-2', 100, '', ), ('uid-3', 7, '', )]
        )
Ejemplo n.º 8
0
 def available(self):
     available = self.stock.available
     shared_stock_data = ISharedStockData(self.context)
     related_uids = shared_stock_data.related_uids
     if available is not None:
         cart_items = extractitems(readcookie(self.request))
         for item_uid in related_uids:
             for uid, count, comment in cart_items:
                 if uid == item_uid:
                     available -= float(count)
     return available
Ejemplo n.º 9
0
 def available(self):
     available = self.stock.available
     shared_stock_data = ISharedStockData(self.context)
     related_uids = shared_stock_data.related_uids
     if available is not None:
         cart_items = extractitems(readcookie(self.request))
         for item_uid in related_uids:
             for uid, count, comment in cart_items:
                 if uid == item_uid:
                     available -= float(count)
     return available
Ejemplo n.º 10
0
    def validate_count(self, uid, count):
        """Validate setting cart item count for uid.

        uid - Is the cart item UID.
        count - If count is 0, it means that a cart item is going to be
        deleted, which is always allowed. If count is > 0, it's the aggregated
        item count in cart.
        """
        count = float(count)
        # count is 0, return
        if not count:
            return {'success': True, 'error': ''}
        cart_item = get_object_by_uid(self.context, uid)
        item_data = get_item_data_provider(cart_item)
        buyable_event = self.acquire_event(cart_item)
        buyable_event_data = IBuyableEventData(buyable_event)
        # cart count limit is set for all event tickets
        if buyable_event_data.cart_count_limit:
            related_uids = IEventTickets(cart_item).related_uids
            aggregated_count = count
            items = extractitems(readcookie(self.request))
            for ticket_uid in related_uids:
                # we already have count for item to validate
                if uid == ticket_uid:
                    continue
                aggregated_count += float(
                    aggregate_cart_item_count(ticket_uid, items))
            if aggregated_count > buyable_event_data.cart_count_limit:
                message = translate(
                    _('event_tickets_limit_reached',
                      default="Limit of tickets for this event reached"),
                    context=self.request)
                return {'success': False, 'error': message}
        # cart count limit is set for ticket
        elif item_data.cart_count_limit:
            if count > item_data.cart_count_limit:
                message = translate(
                    _('ticket_limit_reached',
                      default="Limit for this ticket reached"),
                    context=self.request)
                return {'success': False, 'error': message}
        # stock check
        item_state = get_item_state(cart_item, self.request)
        if item_state.validate_count(count):
            return {'success': True, 'error': ''}
        # out of stock
        message = translate(_('trying_to_add_more_tickets_than_available',
                              default="Not enough tickets available, abort."),
                            context=self.request)
        return {'success': False, 'error': message}
Ejemplo n.º 11
0
    def validate_count(self, uid, count):
        """Validate setting cart item count for uid.

        uid - Is the cart item UID.
        count - If count is 0, it means that a cart item is going to be
        deleted, which is always allowed. If count is > 0, it's the aggregated
        item count in cart.
        """
        count = float(count)
        # count is 0, return
        if not count:
            return {'success': True, 'error': ''}
        cart_item = get_object_by_uid(self.context, uid)
        item_data = get_item_data_provider(cart_item)
        buyable_event = self.acquire_event(cart_item)
        buyable_event_data = IBuyableEventData(buyable_event)
        # cart count limit is set for all event tickets
        if buyable_event_data.cart_count_limit:
            related_uids = IEventTickets(cart_item).related_uids
            aggregated_count = count
            items = extractitems(readcookie(self.request))
            for ticket_uid in related_uids:
                # we already have count for item to validate
                if uid == ticket_uid:
                    continue
                aggregated_count += float(
                    aggregate_cart_item_count(ticket_uid, items))
            if aggregated_count > buyable_event_data.cart_count_limit:
                message = translate(_(
                    'event_tickets_limit_reached',
                    default="Limit of tickets for this event reached"),
                                    context=self.request)
                return {'success': False, 'error': message}
        # cart count limit is set for ticket
        elif item_data.cart_count_limit:
            if count > item_data.cart_count_limit:
                message = translate(_('ticket_limit_reached',
                                      default="Limit for this ticket reached"),
                                    context=self.request)
                return {'success': False, 'error': message}
        # stock check
        item_state = get_item_state(cart_item, self.request)
        if item_state.validate_count(count):
            return {'success': True, 'error': ''}
        # out of stock
        message = translate(_('trying_to_add_more_tickets_than_available',
                              default="Not enough tickets available, abort."),
                            context=self.request)
        return {'success': False, 'error': message}
Ejemplo n.º 12
0
 def items(self):
     return extractitems(readcookie(self.request))
Ejemplo n.º 13
0
 def items(self):
     return extractitems(readcookie(self.request))