Skip to content

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

Add translation query for sale

fowczareke693adb4942f
diff --git a/saleor/graphql/translations/schema.py b/saleor/graphql/translations/schema.py
index d7bf1562f6..ef54961ec2 100644
--- a/saleor/graphql/translations/schema.py
+++ b/saleor/graphql/translations/schema.py
@@ -1,5 +1,6 @@
import graphene
+from ...discount.models import Sale
from ...page.models import Page
from ...product.models import (
Attribute,
@@ -61,6 +62,7 @@ class DefaultTranslationItem(graphene.Union):
translation_types.ProductVariantStrings,
translation_types.PageStrings,
translation_types.ShippingMethodStrings,
+ translation_types.SaleStrings,
)
@@ -156,3 +158,6 @@ class TranslationQueries(graphene.ObjectType):
elif kind == TranslatableKinds.SHIPPING_METHOD:
_type, shipping_method_id = graphene.Node.from_global_id(id)
return ShippingMethod.objects.filter(pk=shipping_method_id).first()
+ elif kind == TranslatableKinds.SALE:
+ _type, sale_id = graphene.Node.from_global_id(id)
+ return Sale.objects.filter(pk=sale_id).first()
diff --git a/saleor/graphql/translations/types.py b/saleor/graphql/translations/types.py
index 4df71de5b5..48f3460c9c 100644
--- a/saleor/graphql/translations/types.py
+++ b/saleor/graphql/translations/types.py
@@ -362,6 +362,35 @@ class SaleTranslation(BaseTranslationType):
only_fields = ["id", "name"]
+class SaleStrings(CountableDjangoObjectType):
+ translation = graphene.Field(
+ SaleTranslation,
+ language_code=graphene.Argument(
+ LanguageCodeEnum,
+ description="A language code to return the translation for.",
+ required=True,
+ ),
+ description="Returns translated sale fields for the given language code.",
+ resolver=resolve_translation,
+ )
+ sale = graphene.Field(
+ "saleor.graphql.discount.types.Sale",
+ description=(
+ "Sales allow creating discounts for categories, collections "
+ "or products and are visible to all the customers."
+ ),
+ )
+
+ class Meta:
+ model = discount_models.Sale
+ interfaces = [graphene.relay.Node]
+ only_fields = ["id", "name"]
+
+ @permission_required("discount.manage_discounts")
+ def resolve_sale(self, info):
+ return self
+
+
class ShopTranslation(BaseTranslationType):
class Meta:
model = site_models.SiteSettingsTranslation