Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Hide select input if product has no more than one variant
dominik-zeglen7fc23f1d16ff
diff --git a/saleor/product/views.py b/saleor/product/views.pyindex 485326b7ab..8508129da4 100644--- a/saleor/product/views.py+++ b/saleor/product/views.py@@ -63,7 +63,11 @@ def product_details(request, slug, product_id, form=None):variant_picker_data = get_variant_picker_data(product, request.discounts, request.currency)product_attributes = get_product_attributes_data(product)+ # show_variant_picker determines if variant picker is used or select inputshow_variant_picker = all([v.attributes for v in product.variants.all()])+ has_variants = product.variants.count() > 1+ # first_variant is used in hidden input if has_variants is False+ first_variant = product.variants.all()[0]json_ld_data = product_json_ld(product, availability, product_attributes)return TemplateResponse(request, 'product/details.html',@@ -77,7 +81,9 @@ def product_details(request, slug, product_id, form=None):'variant_picker_data': json.dumps(variant_picker_data, default=serialize_decimal),'json_ld_product_data': json.dumps(- json_ld_data, default=serialize_decimal)})+ json_ld_data, default=serialize_decimal),+ 'has_variants': has_variants,+ 'first_variant': first_variant})def product_add_to_cart(request, slug, product_id):diff --git a/templates/product/details.html b/templates/product/details.htmlindex 112963dcb9..a777dea043 100644--- a/templates/product/details.html+++ b/templates/product/details.html@@ -136,7 +136,11 @@<form id="product-form" role="form" class="product-form clearfix" method="post"action="{% url 'product:add-to-cart' product_id=product.pk slug=product.get_slug %}" novalidate>{% csrf_token %}- {% bootstrap_field form.variant %}+ {% if has_variants %}+ {% bootstrap_field form.variant %}+ {% else %}+ <input type="hidden" value="{{ first_variant.pk }}" name="variant" />+ {% endif %}<div class="product__info__quantity">{% bootstrap_field form.quantity %}</div>