def __call__(self,
                 context,
                 product,
                 quantity=1,
                 allow_cache=True,
                 supplier=None):
        """
        :type product: shuup.core.models.Product
        """
        options = PriceDisplayOptions.from_context(context)
        if options.hide_prices:
            return ("", "")

        request = context.get('request')
        priced_products = get_many_cached_price_info(
            request,
            product,
            quantity,
            include_taxes=options.include_taxes,
            supplier=supplier) if allow_cache else None

        if not priced_products:
            priced_children_key = PRICED_CHILDREN_CACHE_KEY % (product.id,
                                                               quantity)
            priced_products = []

            if hasattr(request, priced_children_key):
                priced_children = getattr(request, priced_children_key)
            else:
                priced_children = product.get_priced_children(
                    request, quantity) or [
                        (product,
                         _get_priceful(request, product, quantity, supplier))
                    ]
                setattr(request, priced_children_key, priced_children)

            for child_product, price_info in priced_children:
                if not price_info:
                    continue

                priceful = convert_taxness(request, child_product, price_info,
                                           options.include_taxes)
                priced_products.append(priceful)

            if priced_products and allow_cache:
                cache_many_price_info(request,
                                      product,
                                      quantity,
                                      priced_products,
                                      include_taxes=options.include_taxes,
                                      supplier=supplier)

        if not priced_products:
            return ("", "")

        return (money(priced_products[0].price),
                money(priced_products[-1].price))
Exemple #2
0
    def __call__(self, context, product, quantity=1, allow_cache=True, supplier=None):
        """
        :type product: shuup.core.models.Product
        """
        options = PriceDisplayOptions.from_context(context)
        if options.hide_prices:
            return ("", "")

        request = context.get('request')
        priced_products = get_many_cached_price_info(
            request,
            product,
            quantity,
            include_taxes=options.include_taxes,
            supplier=supplier
        ) if allow_cache else None

        if not priced_products:
            priced_children_key = PRICED_CHILDREN_CACHE_KEY % (product.id, quantity)
            priced_products = []

            if hasattr(request, priced_children_key):
                priced_children = getattr(request, priced_children_key)
            else:
                priced_children = product.get_priced_children(request, quantity) or [
                    (product, _get_priceful(request, product, quantity, supplier))
                ]
                setattr(request, priced_children_key, priced_children)

            for child_product, price_info in priced_children:
                if not price_info:
                    continue

                priceful = convert_taxness(request, child_product, price_info, options.include_taxes)
                priced_products.append(priceful)

            if priced_products and allow_cache:
                cache_many_price_info(
                    request,
                    product,
                    quantity,
                    priced_products,
                    include_taxes=options.include_taxes,
                    supplier=supplier)

        if not priced_products:
            return ("", "")

        return (money(priced_products[0].price), money(priced_products[-1].price))
 def assert_nothing_is_cached():
     # nothing is cached
     assert get_many_cached_price_info(request, product, 1) is None
 def assert_cache_products():
     cache_many_price_info(request, product, 1, [child1_pi, child2_pi])
     assert get_many_cached_price_info(request, product, 1)[0].price == child1_pi.price
     assert get_many_cached_price_info(request, product, 1)[1].price == child2_pi.price
 def assert_nothing_is_cached():
     # nothing is cached
     assert get_many_cached_price_info(request, product, 1) is None
 def assert_cache_products():
     cache_many_price_info(request, product, 1, [child1_pi, child2_pi])
     assert get_many_cached_price_info(request, product, 1)[0].price == child1_pi.price
     assert get_many_cached_price_info(request, product, 1)[1].price == child2_pi.price