Skip to content

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

Add translation query for voucher

fowczarekf2771e7ebf3d
diff --git a/saleor/graphql/translations/schema.py b/saleor/graphql/translations/schema.py
index ef54961ec2..d8d5208fe2 100644
--- a/saleor/graphql/translations/schema.py
+++ b/saleor/graphql/translations/schema.py
@@ -1,6 +1,6 @@
import graphene
-from ...discount.models import Sale
+from ...discount.models import Sale, Voucher
from ...page.models import Page
from ...product.models import (
Attribute,
@@ -63,6 +63,7 @@ class DefaultTranslationItem(graphene.Union):
translation_types.PageStrings,
translation_types.ShippingMethodStrings,
translation_types.SaleStrings,
+ translation_types.VoucherStrings,
)
@@ -161,3 +162,6 @@ class TranslationQueries(graphene.ObjectType):
elif kind == TranslatableKinds.SALE:
_type, sale_id = graphene.Node.from_global_id(id)
return Sale.objects.filter(pk=sale_id).first()
+ elif kind == TranslatableKinds.VOUCHER:
+ _type, voucher_id = graphene.Node.from_global_id(id)
+ return Voucher.objects.filter(pk=voucher_id).first()
diff --git a/saleor/graphql/translations/types.py b/saleor/graphql/translations/types.py
index 48f3460c9c..2a1d2a09f1 100644
--- a/saleor/graphql/translations/types.py
+++ b/saleor/graphql/translations/types.py
@@ -355,6 +355,37 @@ class VoucherTranslation(BaseTranslationType):
only_fields = ["id", "name"]
+class VoucherStrings(CountableDjangoObjectType):
+ translation = graphene.Field(
+ VoucherTranslation,
+ language_code=graphene.Argument(
+ LanguageCodeEnum,
+ description="A language code to return the translation for.",
+ required=True,
+ ),
+ description="Returns translated Voucher fields for the given language code.",
+ resolver=resolve_translation,
+ )
+ voucher = graphene.Field(
+ "saleor.graphql.discount.types.Voucher",
+ # TODO consider move description to variable.
+ description=(
+ "Vouchers allow giving discounts to particular customers on categories, "
+ "collections or specific products. They can be used during checkout by "
+ "providing valid voucher codes."
+ ),
+ )
+
+ class Meta:
+ model = discount_models.Voucher
+ interfaces = [graphene.relay.Node]
+ only_fields = ["id", "name"]
+
+ @permission_required("discount.manage_discounts")
+ def resolve_voucher(self, info):
+ return self
+
+
class SaleTranslation(BaseTranslationType):
class Meta:
model = discount_models.SaleTranslation