Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix sort by translation
michal476bec09d8e9
diff --git a/saleor/product/filters.py b/saleor/product/filters.pyindex 0773fca3da..425de924dd 100644--- a/saleor/product/filters.py+++ b/saleor/product/filters.py@@ -14,12 +14,6 @@ from .models import Product, ProductAttributeDEFAULT_SORT = 'name'-SORT_BY_FIELDS = [{'value': 'name',- 'label': pgettext_lazy('Sort by filter', 'name')},- {'value': 'price',- 'label': pgettext_lazy('Sort by filter', 'price')}]--class ProductFilter(FilterSet):def __init__(self, *args, **kwargs):self.category = kwargs.pop('category')@@ -31,8 +25,10 @@ class ProductFilter(FilterSet):self.filters = OrderedDict(sorted(self.filters.items()))sort_by = OrderingFilter(- label='Sort by',- fields=[(field['value'], field['value']) for field in SORT_BY_FIELDS]+ label=pgettext_lazy('Sort by label', 'Sort by'),+ fields=(+ ('price', 'price'),+ ('name', 'name')))class Meta:@@ -79,3 +75,8 @@ class ProductFilter(FilterSet):def _get_attribute_choices(self, attribute):return [(choice.pk, choice.name) for choice in attribute.values.all()]+++def get_prepared_choices(filter):+ return [(choice[0], choice[1].lower()) for choice in+ filter.filters['sort_by'].field.choices[1::2]]diff --git a/saleor/product/views.py b/saleor/product/views.pyindex 1a793226d8..eb548032c8 100644--- a/saleor/product/views.py+++ b/saleor/product/views.py@@ -7,17 +7,19 @@ from django.core.urlresolvers import reversefrom django.http import HttpResponsePermanentRedirect, JsonResponsefrom django.shortcuts import get_object_or_404, redirectfrom django.template.response import TemplateResponse+from django.utils.translation import pgettext_lazy-from ..cart.utils import set_cart_cookie-from ..core.utils import get_paginator_items, serialize_decimal-from ..settings import PAGINATE_BY-from .filters import DEFAULT_SORT, ProductFilter, SORT_BY_FIELDS+from saleor.product.filters import get_prepared_choices+from .filters import DEFAULT_SORT, ProductFilterfrom .models import Categoryfrom .utils import (products_with_details, products_for_cart,handle_cart_form, get_availability,get_product_images, get_variant_picker_data,get_product_attributes_data,product_json_ld, products_with_availability)+from ..cart.utils import set_cart_cookie+from ..core.utils import get_paginator_items, serialize_decimal+from ..settings import PAGINATE_BYdef product_details(request, slug, product_id, form=None):@@ -131,7 +133,8 @@ def category_index(request, path, category_id):ctx = {'category': category, 'filter': product_filter,'products': products_and_availability,'products_paginated': products_paginated,- 'sort_by_choices': SORT_BY_FIELDS,- 'sort_by_label': sort_by.strip('-'),+ 'sort_by_choices': get_prepared_choices(product_filter),+ 'now_sorted_by': pgettext_lazy(+ 'Product field', sort_by.strip('-')),'is_descending': sort_by.startswith('-')}return TemplateResponse(request, 'category/index.html', ctx)diff --git a/templates/category/index.html b/templates/category/index.htmlindex 6a8878e5ac..6f1be5f9b7 100644--- a/templates/category/index.html+++ b/templates/category/index.html@@ -49,9 +49,9 @@<button class="btn btn-link"><div><span>- {% trans 'Sort by' context 'Category page filters' %}: + {% trans 'Sort by' context 'Category page filters' %}<strong>- {{ sort_by_label }}+ {{ now_sorted_by }}</strong></span><div class="sort-order-icon">@@ -64,7 +64,7 @@</div></button><ul class="sort-list d-none">- {% for choice in sort_by_choices %}+ {% for choice, label in sort_by_choices %}<li><div class="row"><div class="col-6">@@ -72,13 +72,13 @@</div><div class="col-6"><div>- <a href="{% get_sort_by_url choice.value %}">+ <a href="{% get_sort_by_url choice %}"><span>{% trans 'ascending' context 'sort by option' %}</span><div class="sort-order-icon float-right"><img src="{% static "assets/arrow_up.svg" %}"></div></a>- <a href="{% get_sort_by_url choice.value descending=True %}">+ <a href="{% get_sort_by_url choice descending=True %}"><span>{% trans 'descending' context 'sort by option' %}</span><div class="sort-order-icon float-right"><img src="{% static "assets/arrow_down.svg" %}">