def get_product(request, category_slug, brand_slug, product_slug, selected_options=(), include_tax=NOTSET, default_view_tax=NOTSET): """Basic product view""" try: product = Product.objects.get_by_site(active=True, slug=product_slug) except Product.DoesNotExist: return bad_or_missing(request, _('The product you have requested does not exist.')) try: category = Category.objects.get(slug=category_slug) except Category.DoesNotExist: category = None brand = Brand.objects.get(slug=brand_slug) if default_view_tax == NOTSET: default_view_tax = config_value('TAX', 'DEFAULT_VIEW_TAX') if default_view_tax: include_tax = True elif include_tax == NOTSET: include_tax = default_view_tax if default_view_tax: include_tax = True subtype_names = product.get_subtypes() if 'ProductVariation' in subtype_names: selected_options = product.productvariation.unique_option_ids # Display the ConfigurableProduct that this ProductVariation belongs to. product = product.productvariation.parent.product subtype_names = product.get_subtypes() best_discount = find_best_auto_discount(product) extra_context = { 'product': product, 'category': category, 'brand': brand, 'default_view_tax': default_view_tax, 'sale': best_discount, } # Get the template context from the Product. extra_context = product.add_template_context( context=extra_context, request=request, selected_options=selected_options, include_tax=include_tax, default_view_tax=default_view_tax ) if include_tax: tax_amt = get_tax(request.user, product, 1) extra_context['product_tax'] = tax_amt extra_context['price_with_tax'] = product.unit_price + tax_amt template = find_product_template(product, producttypes=subtype_names) context = RequestContext(request, extra_context) return http.HttpResponse(template.render(context))
def get_price_detail(request, product_slug): """Get all price details for a product, returning the response encoded as JSON.""" results = { "success" : False, "message" : _("not available") } price = None if request.method=="POST": reqdata = request.POST else: reqdata = request.GET try: product = Product.objects.get_by_site(active=True, slug=product_slug) found = True prod_slug = product.slug if reqdata.has_key('quantity'): quantity = int(reqdata['quantity']) else: quantity = 1 if 'ConfigurableProduct' in product.get_subtypes(): cp = product.configurableproduct chosen_options = optionids_from_post(cp, reqdata) product = cp.get_product_from_options(chosen_options) if product: price = product.get_qty_price(quantity) base_tax = get_tax(request.user, product, quantity) price_with_tax = price+base_tax results['slug'] = product.slug results['currency_price'] = moneyfmt(price) results['price'] = float(price) results['tax'] = float(base_tax) results['currency_tax'] = moneyfmt(base_tax) results['currency_price_with_tax'] = moneyfmt(price_with_tax) results['price_with_tax'] = float(price_with_tax) results['success'] = True results['message'] = "" except Product.DoesNotExist: found = False data = json_encode(results) if found: return http.HttpResponse(data, mimetype="text/javascript") else: return http.HttpResponseNotFound(data, mimetype="text/javascript")
def get_price_detail(request, product_slug): """Get all price details for a product, returning the response encoded as JSON.""" results = {"success": False, "message": _("not available")} price = None if request.method == "POST": reqdata = request.POST else: reqdata = request.GET try: product = Product.objects.active().get(slug=product_slug) found = True if "quantity" in reqdata: quantity = int(reqdata["quantity"]) else: quantity = 1 if "ConfigurableProduct" in product.get_subtypes(): cp = product.configurableproduct chosen_options = optionids_from_post(cp, reqdata) product = cp.get_product_from_options(chosen_options) if product: price = product.get_qty_price(quantity) base_tax = get_tax(request.user, product, quantity) price_with_tax = price + base_tax currency_code = currency_for_request(request) results["slug"] = product.slug results["currency_price"] = money_format(price, currency_code) results["price"] = float(price) results["tax"] = float(base_tax) results["currency_tax"] = money_format(base_tax, currency_code) results["currency_price_with_tax"] = money_format( price_with_tax, currency_code) results["price_with_tax"] = float(price_with_tax) results["success"] = True results["message"] = "" except Product.DoesNotExist: found = False data = json_encode(results) if found: return http.HttpResponse(data, mimetype="text/javascript") else: return http.HttpResponseNotFound(data, mimetype="text/javascript")
def get_product( request, category_slug, brand_slug, product_slug, selected_options=(), include_tax=NOTSET, default_view_tax=NOTSET, ): """Basic product view""" try: product = Product.objects.get_by_site(active=True, slug=product_slug) except Product.DoesNotExist: return bad_or_missing( request, _("The product you have requested does not exist.") ) try: category = Category.objects.get(slug=category_slug) except Category.DoesNotExist: category = None brand = Brand.objects.get(slug=brand_slug) if default_view_tax == NOTSET: default_view_tax = config_value("TAX", "DEFAULT_VIEW_TAX") if default_view_tax: include_tax = True elif include_tax == NOTSET: include_tax = default_view_tax if default_view_tax: include_tax = True subtype_names = product.get_subtypes() if "ProductVariation" in subtype_names: selected_options = product.productvariation.unique_option_ids # Display the ConfigurableProduct that this ProductVariation belongs to. product = product.productvariation.parent.product subtype_names = product.get_subtypes() best_discount = find_best_auto_discount(product) context = { "product": product, "category": category, "brand": brand, "default_view_tax": default_view_tax, "sale": best_discount, } # Get the template context from the Product. context = product.add_template_context( context=context, request=request, selected_options=selected_options, include_tax=include_tax, default_view_tax=default_view_tax, ) if include_tax: tax_amt = get_tax(request.user, product, 1) context["product_tax"] = tax_amt context["price_with_tax"] = product.unit_price + tax_amt price = context["price_with_tax"] else: price = product.unit_price context["all_prices"] = [ { "currency": currency.iso_4217_code, "price": convert_to_currency(price, currency.iso_4217_code), } for currency in Currency.objects.filter(accepted=True) ] template = find_product_template(product, producttypes=subtype_names) return TemplateResponse(request, template, context)
def get_product(request, category_slug, brand_slug, product_slug, selected_options=(), include_tax=NOTSET, default_view_tax=NOTSET): """Basic product view""" try: product = Product.objects.get_by_site(active=True, slug=product_slug) except Product.DoesNotExist: return bad_or_missing( request, _('The product you have requested does not exist.')) try: category = Category.objects.get(slug=category_slug) except Category.DoesNotExist: category = None brand = Brand.objects.get(slug=brand_slug) if default_view_tax == NOTSET: default_view_tax = config_value('TAX', 'DEFAULT_VIEW_TAX') if default_view_tax: include_tax = True elif include_tax == NOTSET: include_tax = default_view_tax if default_view_tax: include_tax = True subtype_names = product.get_subtypes() if 'ProductVariation' in subtype_names: selected_options = product.productvariation.unique_option_ids # Display the ConfigurableProduct that this ProductVariation belongs to. product = product.productvariation.parent.product subtype_names = product.get_subtypes() best_discount = find_best_auto_discount(product) extra_context = { 'product': product, 'category': category, 'brand': brand, 'default_view_tax': default_view_tax, 'sale': best_discount, } # Get the template context from the Product. extra_context = product.add_template_context( context=extra_context, request=request, selected_options=selected_options, include_tax=include_tax, default_view_tax=default_view_tax) if include_tax: tax_amt = get_tax(request.user, product, 1) extra_context['product_tax'] = tax_amt extra_context['price_with_tax'] = product.unit_price + tax_amt template = find_product_template(product, producttypes=subtype_names) context = RequestContext(request, extra_context) return http.HttpResponse(template.render(context))
def get_product( request, category_slug, brand_slug, product_slug, selected_options=(), include_tax=NOTSET, default_view_tax=NOTSET, ): """Basic product view""" try: product = Product.objects.active().get(slug=product_slug) except Product.DoesNotExist: return bad_or_missing( request, _("The product you have requested does not exist.")) try: category = Category.objects.get(slug=category_slug) except Category.DoesNotExist: category = None brand = Brand.objects.get(slug=brand_slug) if default_view_tax == NOTSET: default_view_tax = config_value("TAX", "DEFAULT_VIEW_TAX") if default_view_tax: include_tax = True elif include_tax == NOTSET: include_tax = default_view_tax if default_view_tax: include_tax = True subtype_names = product.get_subtypes() if "ProductVariation" in subtype_names: selected_options = product.productvariation.unique_option_ids # Display the ConfigurableProduct that this ProductVariation belongs to. product = product.productvariation.parent.product subtype_names = product.get_subtypes() best_discount = find_best_auto_discount(product) context = { "product": product, "category": category, "brand": brand, "default_view_tax": default_view_tax, "sale": best_discount, } # Get the template context from the Product. context = product.add_template_context( context=context, request=request, selected_options=selected_options, include_tax=include_tax, default_view_tax=default_view_tax, ) if include_tax: tax_amt = get_tax(request.user, product, 1) context["product_tax"] = tax_amt context["price_with_tax"] = product.unit_price + tax_amt price = context["price_with_tax"] else: price = product.unit_price context["all_prices"] = [{ "currency": currency.iso_4217_code, "price": convert_to_currency(price, currency.iso_4217_code), } for currency in Currency.objects.filter(accepted=True)] template = find_product_template(product, producttypes=subtype_names) return TemplateResponse(request, template, context)