aboutsummaryrefslogtreecommitdiff
path: root/saleor/graphql
diff options
context:
space:
mode:
authorMarcin Gębala <maarcin.gebala@gmail.com>2016-12-29 13:58:13 +0100
committerMarcin Gębala <maarcin.gebala@gmail.com>2017-01-04 11:22:36 +0100
commita25b71e5d8e95ea365f2e08b660b4354c807892d (patch)
treeb860e77a80a4a00af56a9f1036ccdcb6954099a4 /saleor/graphql
parent126aae22d48e65520fd325b2ddfd550e48a057b4 (diff)
downloadsaleor-frontend-a25b71e5d8e95ea365f2e08b660b4354c807892d.tar.gz
saleor-frontend-a25b71e5d8e95ea365f2e08b660b4354c807892d.tar.bz2
saleor-frontend-a25b71e5d8e95ea365f2e08b660b4354c807892d.zip
Show filters relevant to the current category
Diffstat (limited to 'saleor/graphql')
-rw-r--r--saleor/graphql/api.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/saleor/graphql/api.py b/saleor/graphql/api.py
index 548ae143..4c7bc09e 100644
--- a/saleor/graphql/api.py
+++ b/saleor/graphql/api.py
@@ -193,15 +193,30 @@ class PriceType(graphene.ObjectType):
class Viewer(graphene.ObjectType):
category = graphene.Field(
- CategoryType, pk=graphene.Argument(graphene.Int, required=True))
- attributes = graphene.List(ProductAttributeType)
+ CategoryType,
+ pk=graphene.Argument(graphene.Int, required=True))
+ attributes = graphene.List(
+ ProductAttributeType,
+ category_pk=graphene.Argument(graphene.Int, required=False))
debug = graphene.Field(DjangoDebug, name='__debug')
def resolve_category(self, args, context, info):
return get_object_or_none(Category, pk=args.get('pk'))
def resolve_attributes(self, args, context, info):
- return ProductAttribute.objects.prefetch_related('values').all()
+ category_pk = args.get('category_pk')
+ queryset = ProductAttribute.objects.prefetch_related('values')
+ if category_pk:
+ # Get attributes that are used with product classes
+ # within the given category.
+ product_classes = set(
+ [obj[0] for obj in Product.objects.filter(
+ categories__in=[category_pk]).values_list(
+ 'product_class_id')])
+ queryset = queryset.filter(
+ Q(products_class__in=product_classes) |
+ Q(product_variants_class__in=product_classes))
+ return queryset
class Query(graphene.ObjectType):