diff --git a/core/graphene/object_types.py b/core/graphene/object_types.py index 33af0fec..5f666fa5 100644 --- a/core/graphene/object_types.py +++ b/core/graphene/object_types.py @@ -16,6 +16,7 @@ from core.models import ( AttributeValue, Brand, Category, + CategoryTag, Feedback, Order, OrderProduct, @@ -119,6 +120,7 @@ class CategoryType(DjangoObjectType): NonNull(MinMaxPriceType), description=_("minimum and maximum prices for products in this category, if available."), ) + tags = DjangoFilterConnectionField(lambda: CategoryTagType, description=_("tags for this category")) class Meta: model = Category @@ -464,6 +466,17 @@ class ProductTagType(DjangoObjectType): description = _("product tags") +class CategoryTagType(DjangoObjectType): + category_set = DjangoFilterConnectionField(CategoryType, description=_("tagged categories")) + + class Meta: + model = CategoryTag + interfaces = (relay.Node,) + fields = ("uuid", "tag_name", "name", "category_set") + filter_fields = ["uuid", "tag_name", "name"] + description = _("categories tags") + + class ConfigType(ObjectType): project_name = String(description=_("project name")) base_domain = String(description=_("company email")) diff --git a/core/graphene/schema.py b/core/graphene/schema.py index 986c952f..d42c8392 100644 --- a/core/graphene/schema.py +++ b/core/graphene/schema.py @@ -41,6 +41,7 @@ from core.graphene.mutations import ( from core.graphene.object_types import ( AttributeGroupType, BrandType, + CategoryTagType, CategoryType, ConfigType, FeedbackType, @@ -60,6 +61,7 @@ from core.models import ( AttributeGroup, Brand, Category, + CategoryTag, Feedback, Order, OrderProduct, @@ -111,6 +113,7 @@ class Query(ObjectType): stocks = DjangoFilterConnectionField(StockType) wishlists = DjangoFilterConnectionField(WishlistType, filterset_class=WishlistFilter) product_tags = DjangoFilterConnectionField(ProductTagType) + category_tags = DjangoFilterConnectionField(CategoryTagType) promotions = DjangoFilterConnectionField(PromotionType) promocodes = DjangoFilterConnectionField(PromoCodeType) brands = DjangoFilterConnectionField(BrandType, filterset_class=BrandFilter) @@ -289,6 +292,12 @@ class Query(ObjectType): return ProductTag.objects.all() return ProductTag.objects.filter(is_active=True) + @staticmethod + def resolve_category_tags(_parent, info, **kwargs): + if info.context.user.has_perm("core.view_categorytag"): + return CategoryTag.objects.all() + return CategoryTag.objects.filter(is_active=True) + class Mutation(ObjectType): search = Search.Field()