Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Allow to filter out products without category in api
IKarbowiak35b42a80038a
diff --git a/saleor/graphql/product/filters.py b/saleor/graphql/product/filters.pyindex fccea17270..359813e4d1 100644--- a/saleor/graphql/product/filters.py+++ b/saleor/graphql/product/filters.py@@ -121,6 +121,10 @@ def filter_categories(qs, _, value):return qs+def filter_has_category(qs, _, value):+ return qs.filter(category__isnull=not value)++def filter_collections(qs, _, value):if value:collections = get_nodes(value, types.Collection)@@ -214,6 +218,7 @@ class ProductFilter(django_filters.FilterSet):is_published = django_filters.BooleanFilter()collections = GlobalIDMultipleChoiceFilter(method=filter_collections)categories = GlobalIDMultipleChoiceFilter(method=filter_categories)+ has_category = django_filters.BooleanFilter(method=filter_has_category)price = ObjectTypeFilter(input_class=PriceRangeInput, method=filter_price, field_name="price_amount")@@ -237,6 +242,7 @@ class ProductFilter(django_filters.FilterSet):"is_published","collections","categories",+ "has_category","price","attributes","stock_availability",diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 7b618ddab9..16e09e8535 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -2977,6 +2977,7 @@ input ProductFilterInput {isPublished: Booleancollections: [ID]categories: [ID]+ hasCategory: Booleanprice: PriceRangeInputattributes: [AttributeInput]stockAvailability: StockAvailability