diff options
author | Marcin Gębala <maarcin.gebala@gmail.com> | 2016-12-30 16:13:19 +0100 |
---|---|---|
committer | Marcin Gębala <maarcin.gebala@gmail.com> | 2017-01-04 11:22:36 +0100 |
commit | 0b85734c1a3b0bc0061d1629f1557cc57cf7b243 (patch) | |
tree | ae1551728acd4848f7038b1f724dc1fde8e1be49 /saleor/graphql | |
parent | 59ed52d67ac18460bc456b0b21aab9a985223f69 (diff) | |
download | saleor-frontend-0b85734c1a3b0bc0061d1629f1557cc57cf7b243.tar.gz saleor-frontend-0b85734c1a3b0bc0061d1629f1557cc57cf7b243.tar.bz2 saleor-frontend-0b85734c1a3b0bc0061d1629f1557cc57cf7b243.zip |
Filter by price including discounts
Diffstat (limited to 'saleor/graphql')
-rw-r--r-- | saleor/graphql/api.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/saleor/graphql/api.py b/saleor/graphql/api.py index 68f24b90..35e4497f 100644 --- a/saleor/graphql/api.py +++ b/saleor/graphql/api.py @@ -94,6 +94,11 @@ class CategoryType(DjangoObjectType): return self.get_siblings() def resolve_products(self, args, context, info): + + def filter_by_price(queryset, value, operator): + return [obj for obj in queryset if operator(get_availability( + obj, context.discounts).price_range.min_price.gross, value)] + tree = self.get_descendants(include_self=True) qs = Product.objects.prefetch_for_api().filter(categories__in=tree) attributes_filter = args.get('attributes') @@ -135,17 +140,17 @@ class CategoryType(DjangoObjectType): Q(**{'attributes__%s' % key: v}) for v in values]) for key, values in queries.items()] query = reduce(operator.and_, combine_and) - qs = qs.filter(query) + qs = qs.filter(query).distinct() if order_by: qs = qs.order_by(order_by) if price_lte: - qs = qs.filter(price__lte=price_lte) + qs = filter_by_price(qs, price_lte, operator.le) if price_gte: - qs = qs.filter(price__gte=price_gte) - return qs.distinct() + qs = filter_by_price(qs, price_gte, operator.ge) + return qs def resolve_products_count(self, args, context, info): return self.products.count() |