def get_products_for_categories(context, categories, n_products=6, orderable_only=True, sale_items_only=False): request = context["request"] key, product_ids = context_cache.get_cached_value( identifier="products_for_category", item=cache_utils.get_products_for_category_cache_item(request.shop), context=request, n_products=n_products, categories=categories, orderable_only=orderable_only, sale_items_only=sale_items_only) if product_ids is not None and _can_use_cache(product_ids, request.shop, request.customer): return Product.objects.filter(id__in=product_ids) products = get_listed_products(context, n_products, ordering="?", filter_dict={ "variation_parent": None, "shop_products__categories__in": categories }, orderable_only=orderable_only, sale_items_only=sale_items_only) products = cache_product_things(request, products) product_ids = [product.id for product in products] context_cache.set_cached_value( key, product_ids, settings.SHUUP_TEMPLATE_HELPERS_CACHE_DURATION) return products
def get_products_for_categories(context, categories, n_products=6, orderable_only=True): request = context["request"] key, products = context_cache.get_cached_value( identifier="products_for_category", item=cache_utils.get_products_for_category_cache_item(request.shop), context=request, n_products=n_products, categories=categories, orderable_only=orderable_only) if products is not None: return products products = _get_listed_products(context, n_products, ordering="?", filter_dict={ "variation_parent": None, "shop_products__categories__in": categories }, orderable_only=orderable_only) products = cache_product_things(request, products) context_cache.set_cached_value( key, products, settings.SHUUP_TEMPLATE_HELPERS_CACHE_DURATION) return products
def get_products_for_categories(context, categories, n_products=6, orderable_only=True): request = context["request"] key, products = context_cache.get_cached_value( identifier="products_for_category", item=cache_utils.get_products_for_category_cache_item(request.shop), context=request, n_products=n_products, categories=categories, orderable_only=orderable_only ) if products is not None: return products products = _get_listed_products( context, n_products, ordering="?", filter_dict={ "variation_parent": None, "shop_products__categories__in": categories }, orderable_only=orderable_only ) products = cache_product_things(request, products) context_cache.set_cached_value(key, products, settings.SHUUP_TEMPLATE_HELPERS_CACHE_DURATION) return products
def handle_context_cache_item_bumped(sender, item, **kwargs): """ Every time the context cache is bumped for a ShopProduct we bump the context cache for template helpers for the item's shop """ if isinstance(item, ShopProduct): shop = item.shop context_cache.bump_cache_for_item(cache_utils.get_best_selling_products_cache_item(shop)) context_cache.bump_cache_for_item(cache_utils.get_newest_products_cache_item(shop)) context_cache.bump_cache_for_item(cache_utils.get_products_for_category_cache_item(shop)) context_cache.bump_cache_for_item(cache_utils.get_random_products_cache_item(shop))
def bump_cache_for_shop_id(shop_id): context_cache.bump_cache_for_item( cache_utils.get_listed_products_cache_item(shop_id)) context_cache.bump_cache_for_item( cache_utils.get_best_selling_products_cache_item(shop_id)) context_cache.bump_cache_for_item( cache_utils.get_newest_products_cache_item(shop_id)) context_cache.bump_cache_for_item( cache_utils.get_products_for_category_cache_item(shop_id)) context_cache.bump_cache_for_item( cache_utils.get_random_products_cache_item(shop_id))
def handle_context_cache_item_bumped(sender, item, **kwargs): """ Every time the context cache is bumped for a ShopProduct we bump the context cache for template helpers for the item's shop """ if isinstance(item, ShopProduct): shop = item.shop context_cache.bump_cache_for_item(cache_utils.get_listed_products_cache_item(shop)) context_cache.bump_cache_for_item(cache_utils.get_best_selling_products_cache_item(shop)) context_cache.bump_cache_for_item(cache_utils.get_newest_products_cache_item(shop)) context_cache.bump_cache_for_item(cache_utils.get_products_for_category_cache_item(shop)) context_cache.bump_cache_for_item(cache_utils.get_random_products_cache_item(shop)) bump_product_queryset_cache() elif isinstance(item, Product): bump_product_queryset_cache()
def handle_context_cache_item_bumped(sender, item, shop=None, **kwargs): """ Every time the context cache is bumped for a ShopProduct we bump the context cache for template helpers for the item's shop """ if issubclass(sender, ShopProduct): if not shop and isinstance(item, int): shop = ShopProduct.objects.get(id=item).shop elif not shop: shop = item.shop context_cache.bump_cache_for_item(cache_utils.get_listed_products_cache_item(shop)) context_cache.bump_cache_for_item(cache_utils.get_best_selling_products_cache_item(shop)) context_cache.bump_cache_for_item(cache_utils.get_newest_products_cache_item(shop)) context_cache.bump_cache_for_item(cache_utils.get_products_for_category_cache_item(shop)) context_cache.bump_cache_for_item(cache_utils.get_random_products_cache_item(shop)) bump_product_queryset_cache() elif issubclass(sender, Product): bump_product_queryset_cache()