def product_details(request, slug, product_id): products = Product.objects.select_subclasses() products = products.select_related('category') products = products.prefetch_related('images') product = get_object_or_404(products, id=product_id) if product.get_slug() != slug: return HttpResponsePermanentRedirect(product.get_absolute_url()) form_class = get_form_class_for_product(product) cart = Cart.for_session_cart(request.cart, discounts=request.discounts) form = form_class(cart=cart, product=product, data=request.POST or None) if form.is_valid(): if form.cleaned_data['quantity']: msg = _('Added %(product)s to your cart.') % { 'product': product} messages.success(request, msg) form.save() return redirect('product:details', slug=slug, product_id=product_id) template_name = 'product/details_%s.html' % ( type(product).__name__.lower(),) templates = [template_name, 'product/details.html'] related_products = get_related_products(product) return TemplateResponse( request, templates, {'product': product, 'form': form, 'related_products': related_products})
def product_details(request, slug, product_id): products = Product.objects.get_available_products().select_subclasses() products = products.prefetch_related("categories", "images", "variants__stock") product = get_object_or_404(products, id=product_id) if product.get_slug() != slug: return HttpResponsePermanentRedirect(product.get_absolute_url()) form_class = get_form_class_for_product(product) cart = Cart.for_session_cart(request.cart, discounts=request.discounts) form = form_class(cart=cart, product=product, data=request.POST or None) if form.is_valid(): if form.cleaned_data["quantity"]: action = request.POST.get("action") if action == "submit": msg = _("Added %(product)s to your cart.") % {"product": product} messages.success(request, msg) form.save() return redirect("product:details", slug=slug, product_id=product_id) elif action == "subscribe": msg = _("Subscription requested") % {"product": product} # subscribe(request,slug,product_id) messages.success(request, msg) template_name = "product/details_%s.html" % (type(product).__name__.lower(),) templates = [template_name, "product/details.html"] return TemplateResponse(request, templates, {"product": product, "form": form})
def product_details(request, slug, product_id): products = Product.objects.get_available_products().select_subclasses() products = products.prefetch_related('categories', 'images', 'variants__stock') product = get_object_or_404(products, id=product_id) if product.get_slug() != slug: return HttpResponsePermanentRedirect(product.get_absolute_url()) form_class = get_form_class_for_product(product) cart = Cart.for_session_cart(request.cart, discounts=request.discounts) form = form_class(cart=cart, product=product, data=request.POST or None) if form.is_valid(): if form.cleaned_data['quantity']: action = request.POST.get('action') if action == 'submit': msg = _('Added %(product)s to your cart.') % { 'product': product} messages.success(request, msg) form.save() return redirect('product:details', slug=slug, product_id=product_id) elif action == 'subscribe': msg = _('Subscription requested') % { 'product': product} #subscribe(request,slug,product_id) messages.success(request,msg) template_name = 'product/details_%s.html' % ( type(product).__name__.lower(),) templates = [template_name, 'product/details.html'] return TemplateResponse( request, templates, {'product': product, 'form': form})
def product_details(request, slug, product_id): product = get_object_or_404(Product, id=product_id) if product.get_slug() != slug: return HttpResponsePermanentRedirect(product.get_absolute_url()) form_class = get_form_class_for_product(product) cart = Cart.for_session_cart(request.cart) form = form_class(cart=cart, product=product, data=request.POST or None) if form.is_valid(): if form.cleaned_data['quantity']: msg = _('Added %(product)s to your cart.') % { 'product': product} messages.success(request, msg) form.save() return redirect('product:details', slug=slug, product_id=product_id) template_name = 'product/details_%s.html' % ( product.__class__.__name__.lower() ) return TemplateResponse(request, [template_name, 'product/details.html'], { 'product': product, 'form': form})
def product_details(request, slug, product_id): product = get_object_or_404(Product.objects.select_subclasses(), id=product_id) if product.get_slug() != slug: return HttpResponsePermanentRedirect(product.get_absolute_url()) form_class = get_form_class_for_product(product) cart = Cart.for_session_cart(request.cart, discounts=request.discounts) form = form_class(cart=cart, product=product, data=request.POST or None) if form.is_valid(): if form.cleaned_data['quantity']: msg = _('Added %(product)s to your cart.') % { 'product': product} messages.success(request, msg) form.save() return redirect('product:details', slug=slug, product_id=product_id) template_name = 'product/details_%s.html' % ( type(product).__name__.lower(),) templates = [template_name, 'product/details.html'] related_products = get_related_products(product) return TemplateResponse( request, templates, {'product': product, 'form': form, 'related_products': related_products})