Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add filtering by subcategories

Marcin Gębalaaf8efae20bcd
diff --git a/saleor/graphql/api.py b/saleor/graphql/api.py
index 983b890da8..d65addb3c3 100644
--- a/saleor/graphql/api.py
+++ b/saleor/graphql/api.py
@@ -61,7 +61,10 @@ class CategoryType(DjangoObjectType):
than or equal to the given value"""),
price_gte=graphene.Argument(
graphene.Float, description="""Get the products with price greater
- than or equal to the given value"""))
+ than or equal to the given value"""),
+ subcategories=graphene.Argument(
+ graphene.List(graphene.String, description="""A list of
+ subcategories slugs to filter the products by""")))
products_count = graphene.Int()
url = graphene.String()
children = graphene.List(lambda: CategoryType)
@@ -83,6 +86,7 @@ class CategoryType(DjangoObjectType):
order_by = args.get('order_by')
price_lte = args.get('price_lte')
price_gte = args.get('price_gte')
+ subcategories_filter = args.get('subcategories')
if attributes_filter:
attributes = ProductAttribute.objects.prefetch_related('values')
attributes_map = {attribute.name: attribute.pk
@@ -126,6 +130,8 @@ class CategoryType(DjangoObjectType):
qs = qs.filter(price__lte=price_lte)
if price_gte:
qs = qs.filter(price__gte=price_gte)
+ if subcategories_filter:
+ qs = qs.filter(categories__slug__in=subcategories_filter)
return qs.distinct()
def resolve_products_count(self, args, context, info):