Beispiel #1
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.
        """
        cart_item = utils.get_object_by_uid(self.context, uid)
        item_data = cartitem.get_item_data_provider(cart_item)
        cart_count_limit = item_data.cart_count_limit
        if cart_count_limit and float(count) > cart_count_limit:
            message = translate(
                _("article_limit_reached", default="Article limit reached"),
                context=self.request,
            )
            return {"success": False, "error": message, "update": False}
        item_state = cartitem.get_item_state(cart_item, self.request)
        if item_state.validate_count(count):
            return {"success": True, "error": ""}
        message = translate(
            _(
                "trying_to_add_more_items_than_available",
                default="Not enough items available, abort.",
            ),
            context=self.request,
        )
        return {"success": False, "error": message, "update": False}
Beispiel #2
0
def cart_item_free_shipping(context, item):
    """Return boolean whether cart item shipping is free.
    """
    obj = utils.get_object_by_uid(context, item[0])
    if not obj:
        return False
    shipping = get_item_shipping(obj)
    if shipping:
        return shipping.free_shipping
    return False
Beispiel #3
0
def cart_item_shippable(context, item):
    """Return boolean whether cart item is shippable.
    """
    obj = utils.get_object_by_uid(context, item[0])
    if not obj:
        return False
    shipping = get_item_shipping(obj)
    if shipping:
        return shipping.shippable
    return False
 def product_group(self):
     uid = self.request.get("uid")
     if not uid:
         raise ValueError(u"No execution context UID")
     obj = get_object_by_uid(self.context, uid)
     if not obj:
         raise ValueError(u"Execution context object not found by UID")
     if IProductGroup.providedBy(obj):
         return obj
     if IVariant.providedBy(obj):
         return aq_parent(obj)
     raise ValueError(u"Object not implements IProductGroup or IVariant")