Skip to content

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

Add translation query for Collection

fowczareka213a90ec6f8
diff --git a/saleor/graphql/translations/schema.py b/saleor/graphql/translations/schema.py
index 36eacc992a..eaf7ae8a32 100644
--- a/saleor/graphql/translations/schema.py
+++ b/saleor/graphql/translations/schema.py
@@ -1,6 +1,6 @@
import graphene
-from ...product.models import Product
+from ...product.models import Collection, Product
from ..core.connection import CountableConnection
from ..core.fields import BaseConnectionField
from ..decorators import permission_required
@@ -43,7 +43,7 @@ class TranslatableItem(graphene.Union):
# TODO Consider name of this class
class DefaultTranslationItem(graphene.Union):
class Meta:
- types = (translation_types.ProductStrings,)
+ types = (translation_types.ProductStrings, translation_types.CollectionStrings)
class TranslatableItemConnection(CountableConnection):
@@ -110,7 +110,10 @@ class TranslationQueries(graphene.ObjectType):
@permission_required("site.manage_translations")
def resolve_translation(self, info, id, kind, **_kwargs):
+ # TODO Add other translatable items
if kind == TranslatableKinds.PRODUCT:
_type, product_id = graphene.Node.from_global_id(id)
return Product.objects.filter(pk=product_id).first()
- # TODO Add other translatable items
+ elif kind == TranslatableKinds.COLLECTION:
+ _type, collection_id = graphene.Node.from_global_id(id)
+ return Collection.objects.filter(pk=collection_id).first()
diff --git a/saleor/graphql/translations/types.py b/saleor/graphql/translations/types.py
index bcd6fb746b..70ae9eeea6 100644
--- a/saleor/graphql/translations/types.py
+++ b/saleor/graphql/translations/types.py
@@ -122,6 +122,44 @@ class CollectionTranslation(BaseTranslationType):
]
+class CollectionStrings(CountableDjangoObjectType):
+ translation = graphene.Field(
+ CollectionTranslation,
+ language_code=graphene.Argument(
+ LanguageCodeEnum,
+ description="A language code to return the translation for.",
+ required=True,
+ ),
+ description=(
+ "Returns translated Collection fields " "for the given language code."
+ ),
+ resolver=resolve_translation,
+ )
+ collection = graphene.Field(
+ "saleor.graphql.product.types.products.Collection",
+ description="Represents a collection of products.",
+ )
+
+ class Meta:
+ model = product_models.Collection
+ interfaces = [graphene.relay.Node]
+ only_fields = [
+ "description",
+ "description_json",
+ "id",
+ "name",
+ "seo_title",
+ "seo_description",
+ ]
+
+ def resolve_collection(self, info):
+ return (
+ product_models.Collection.objects.visible_to_user(info.context.user)
+ .filter(pk=self.id)
+ .first()
+ )
+
+
class CategoryTranslation(BaseTranslationType):
class Meta:
model = product_models.CategoryTranslation