Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add sort by to filters
michalc64499a75ba4
diff --git a/saleor/product/filters.py b/saleor/product/filters.pyindex 29b0951b8e..d5a8f0d3a1 100644--- a/saleor/product/filters.py+++ b/saleor/product/filters.py@@ -1,6 +1,7 @@from collections import OrderedDict-from django_filters import FilterSet, MultipleChoiceFilter, RangeFilter+from django_filters import FilterSet, MultipleChoiceFilter, RangeFilter, \+ OrderingFilterfrom django.forms import CheckboxSelectMultiplefrom django_prices.models import PriceField@@ -36,6 +37,12 @@ class ProductFilter(FilterSet):choices=get_attribute_choices(attribute))self.filters = OrderedDict(sorted(self.filters.items()))+ sort_by = OrderingFilter(+ label='Sort by',+ fields=(('price', 'price'),+ ('name', 'name'))+ )+class Meta:model = Productfields = ['price']diff --git a/templates/category/index.html b/templates/category/index.htmlindex eafd7ef79a..b2961798ef 100644--- a/templates/category/index.html+++ b/templates/category/index.html@@ -41,19 +41,18 @@<li><a href='{{ category.get_absolute_url }}'>{{ category.name }}</a></li></ul></div>- <!--<div class="col-md-5">-->- <!--<div class="row">-->- <!--<div class="col-6 col-md-2 col-lg-6 filters-menu">-->- <!--<span class="filters-menu__label d-sm-none" onClick={() => this.toggleMenu(filtersMenu)}>{pgettext('Category page filters', 'Filters')}</span>-->- <!--{(variables.attributesFilter.length || variables.minPrice || variables.maxPrice) && (-->- <!--<span class="filters-menu__icon d-sm-none"></span>-->- <!--)}-->- <!--</div>-->- <!--<div class="col-6 col-md-10 col-lg-6">-->- <!--<SortBy sortedValue={variables.sortBy} setSorting={this.setSorting} />-->- <!--</div>-->- <!--</div>-->- <!--</div>-->+ <div class="col-md-5">+ <div class="row">+ {% with filter.form.sort_by as field %}+ <div class="col-6 col-md-2 col-lg-6 filters-menu">+ {{ field.label }}:+ </div>+ <div class="col-6 col-md-10 col-lg-6">+ {{ field }}+ </div>+ {% endwith %}+ </div>+ </div></div></div><div class="row">@@ -69,18 +68,20 @@<div class="product-filters"><div class="product-filters__attributes"><form method="get">- <!--{% csrf_token %}-->{% for field in filter.form %}- <div key={{ attribute.pk }}>- <h3 onClick="">- {{ field.label }}- <!--<div class="collapse-filters-icon">-->- <!--<InlineSVG key={key} src={imageSrc} />-->- <!--</div>-->- </h3>- {{ field }}+ {% if field.label != 'Sort by' %}+ <div key={{ attribute.pk }}>+ <h3 onClick="">+ {{ field.label }}+ <!--<div class="collapse-filters-icon">-->+ <!--<InlineSVG key={key} src={imageSrc} />-->+ <!--</div>-->+ </h3>+ {{ field }}- </div>++ </div>+ {% endif %}{% endfor %}<button type="submit">Search</button></form>@@ -91,7 +92,7 @@<div class="col-md-8 col-lg-9 category-list"><div><!--ProductList-->- {{ filter.qs.count }}+ Items found: {{ filter.qs.count }}{% for product in filter.qs %}<div class="row">