Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Review changes
michald03a11f87d90
diff --git a/saleor/product/filters.py b/saleor/product/filters.pyindex 300480ee29..32f4cec236 100644--- a/saleor/product/filters.py+++ b/saleor/product/filters.py@@ -24,10 +24,10 @@ class ProductFilter(FilterSet):def __init__(self, *args, **kwargs):self.category = kwargs.pop('category')super(ProductFilter, self).__init__(*args, **kwargs)- self.product_attributes, self.variant_attributes = \- self._get_attributes(self.category)- self._add_product_attributes_filters()- self._add_product_variants_attributes_filters()+ self.product_attributes, self.variant_attributes = (+ self._get_attributes())+ self.filters.update(self._add_product_attributes_filters())+ self.filters.update(self._add_product_variants_attributes_filters())self.filters = OrderedDict(sorted(self.filters.items()))sort_by = OrderingFilter(@@ -44,34 +44,38 @@ class ProductFilter(FilterSet):}}- def _get_attributes(self, category):- product_attributes = \- (ProductAttribute.objects.all()- .prefetch_related('values')- .filter(products_class__products__categories=category)- .distinct())- variant_attributes = \- (ProductAttribute.objects.all()- .prefetch_related('values')- .filter(product_variants_class__products__categories=category)- .distinct())+ def _get_attributes(self):+ product_attributes = (+ ProductAttribute.objects.all()+ .prefetch_related('values')+ .filter(products_class__products__categories=self.category)+ .distinct())+ variant_attributes = (+ ProductAttribute.objects.all()+ .prefetch_related('values')+ .filter(product_variants_class__products__categories=self.category)+ .distinct())return product_attributes, variant_attributesdef _add_product_attributes_filters(self):+ filters = {}for attribute in self.product_attributes:- self.filters[attribute.slug] = MultipleChoiceFilter(+ filters[attribute.slug] = MultipleChoiceFilter(name='attributes__%s' % attribute.pk,label=attribute.name,widget=CheckboxSelectMultiple,choices=self._get_attribute_choices(attribute))+ return filtersdef _add_product_variants_attributes_filters(self):+ filters = {}for attribute in self.variant_attributes:- self.filters[attribute.slug] = MultipleChoiceFilter(+ filters[attribute.slug] = MultipleChoiceFilter(name='variants__attributes__%s' % attribute.pk,label=attribute.name,widget=CheckboxSelectMultiple,choices=self._get_attribute_choices(attribute))+ return filtersdef _get_attribute_choices(self, attribute):return [(choice.pk, choice.name) for choice in attribute.values.all()]diff --git a/saleor/product/templatetags/sort_by.py b/saleor/product/templatetags/sort_by.pyindex 8b590a3ee9..58395c07db 100644--- a/saleor/product/templatetags/sort_by.py+++ b/saleor/product/templatetags/sort_by.py@@ -5,7 +5,7 @@ register = template.Library()@register.inclusion_tag('category/_sort_by.html', takes_context=True)def sort_by(context, attribute):- context['label'] = attribute['label']- context['ascending_attribute'] = attribute['value']- context['descending_attribute'] = '-' + str(attribute['value'])- return context+ return {'request': context['request'],+ 'label': attribute['label'],+ 'ascending_attribute': attribute['value'],+ 'descending_attribute': '-' + str(attribute['value'])}diff --git a/saleor/product/templatetags/sort_menu.py b/saleor/product/templatetags/sort_menu.pyindex aa661fbf35..abccd55533 100644--- a/saleor/product/templatetags/sort_menu.py+++ b/saleor/product/templatetags/sort_menu.py@@ -7,9 +7,11 @@ register = template.Library()@register.inclusion_tag('category/_sort_menu.html', takes_context=True)def sort_menu(context, attributes):- context['sort_by'] = \- context['request'].GET.get('sort_by', DEFAULT_SORT).strip('-')- context['sort_by_choices'] = attributes- context['arrow_down'] = \- (context['request'].GET.get('sort_by', DEFAULT_SORT).startswith('-'))- return context+ ctx = {+ 'request': context['request'],+ 'sort_by':+ context['request'].GET.get('sort_by', DEFAULT_SORT).strip('-'),+ 'sort_by_choices': attributes,+ 'arrow_down':+ context['request'].GET.get('sort_by', DEFAULT_SORT).startswith('-')}+ return ctxdiff --git a/saleor/product/views.py b/saleor/product/views.pyindex e218285ad1..3581c8671d 100644--- a/saleor/product/views.py+++ b/saleor/product/views.py@@ -130,6 +130,5 @@ 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,- 'show_pagination': len(products) > PAGINATE_BY}+ 'sort_by_choices': SORT_BY_FIELDS}return TemplateResponse(request, 'category/index.html', ctx)diff --git a/templates/category/index.html b/templates/category/index.htmlindex aa511f1e0e..45be775c97 100644--- a/templates/category/index.html+++ b/templates/category/index.html@@ -132,7 +132,7 @@</div><div class="row"><div class="m-auto">- {% if show_pagination %}+ {% if products_paginated.has_other_pages %}{% bootstrap_pagination products_paginated extra=request.GET.urlencode %}{% endif %}</div>