def test_variation_product_price_more_complex(rf): shop = get_default_shop() supplier = get_default_supplier(shop) product_data = { "supplier-1": { "sizes": ["S", "M"], "colors": ["Black", "Yellow"], }, "supplier-2": { "sizes": ["XL"], "colors": ["Yellow"], }, } parent = create_product("ComplexVarParent", shop=shop) shop_parent_product = parent.get_shop_instance(shop) for key, data in six.iteritems(product_data): supplier = Supplier.objects.create(identifier=key) supplier.shops.add(shop) for size in data["sizes"]: for color in data["colors"]: sku = "ComplexVarChild-%s-%s" % (size, color) shop_product = ShopProduct.objects.filter( product__sku=sku).first() if shop_product: shop_product.suppliers.add(supplier) else: child = create_product(sku, shop=shop, supplier=supplier) child.link_to_parent(parent, variables={ "size": size, "color": color }) assert parent.variation_children.count() == 5 # We have 6 different combinations but only 5 combinations # has product in them. assert len(list(parent.get_all_available_combinations())) == 6 request = apply_request_middleware(rf.get("/")) request.shop = shop supplier1 = Supplier.objects.get(identifier="supplier-1") # For cache for x in range(0, 1): context = get_product_context(request, parent, supplier=supplier1) assert len(context["orderable_variation_children"]) == 2 for variation_variable, variable_values in six.iteritems( context["orderable_variation_children"]): assert len(variable_values) == 2 supplier2 = Supplier.objects.get(identifier="supplier-2") # For cache for x in range(0, 1): context = get_product_context(request, parent, supplier=supplier2) assert len(context["orderable_variation_children"]) == 2 for variation_variable, variable_values in six.iteritems( context["orderable_variation_children"]): assert len(variable_values) == 1
def get_context_data(self, **kwargs): context = super(ProductDetailView, self).get_context_data(**kwargs) language = self.language = get_language() context.update(get_product_context(self.request, self.object, language)) # TODO: Maybe add hook for ProductDetailView get_context_data? # dispatch_hook("get_context_data", view=self, context=context) return context
def get_context_data(self, **kwargs): context = super(ProductDetailView, self).get_context_data(**kwargs) language = self.language = get_language() context.update(get_product_context(self.request, self.object, language)) # TODO: Maybe add hook for ProductDetailView get_context_data? # dispatch_hook("get_context_data", view=self, context=context) return context
def get_context_data(self, **kwargs): context = super(ProductDetailView, self).get_context_data(**kwargs) language = self.language = get_language() supplier_pk = self.kwargs.get("supplier_pk") if supplier_pk: supplier = Supplier.objects.enabled().filter(id=supplier_pk, shops=self.request.shop).first() else: shop_product = self.object.get_shop_instance(self.request.shop, allow_cache=True) supplier = shop_product.get_supplier(self.request.customer) context.update(get_product_context(self.request, self.object, language, supplier)) # TODO: Maybe add hook for ProductDetailView get_context_data? # dispatch_hook("get_context_data", view=self, context=context) return context
def get_context_data(self, **kwargs): context = super(ProductDetailView, self).get_context_data(**kwargs) language = self.language = get_language() supplier = None supplier_pk = self.kwargs.get("supplier_pk") if supplier_pk: supplier = Supplier.objects.filter( id=supplier_pk, shops=self.request.shop).first() context.update( get_product_context(self.request, self.object, language, supplier)) # TODO: Maybe add hook for ProductDetailView get_context_data? # dispatch_hook("get_context_data", view=self, context=context) return context
def get_context_data(self, **kwargs): context = super(ProductDetailView, self).get_context_data(**kwargs) language = self.language = get_language() supplier_pk = self.kwargs.get("supplier_pk") if supplier_pk: supplier = Supplier.objects.enabled(shop=self.request.shop).filter(id=supplier_pk).first() else: shop_product = self.object.get_shop_instance(self.request.shop, allow_cache=True) supplier = shop_product.get_supplier(self.request.customer) context.update(get_product_context(self.request, self.object, language, supplier)) # TODO: Maybe add hook for ProductDetailView get_context_data? # dispatch_hook("get_context_data", view=self, context=context) return context