Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add mutation for activate gift card
fowczarek9624aa68d5c0
diff --git a/saleor/graphql/giftcard/mutations.py b/saleor/graphql/giftcard/mutations.pyindex 0bb7f817e8..a0a8435157 100644--- a/saleor/graphql/giftcard/mutations.py+++ b/saleor/graphql/giftcard/mutations.py@@ -96,9 +96,31 @@ class GiftCardDeactivate(BaseMutation):gift_card = cls.get_node_or_error(info, gift_card_id, field="gift_card_id", only_type=GiftCard)- gift_card.is_active = False- gift_card.last_used_on = date.today()- gift_card.save()+ if gift_card.is_active:+ gift_card.is_active = False+ gift_card.save(update_fields=["is_active"])+ return GiftCardDeactivate(gift_card=gift_card)+++class GiftCardActivate(BaseMutation):+ gift_card = graphene.Field(GiftCard, description="A gift card to activate.")++ class Arguments:+ id = graphene.ID(required=True, description="ID of a gift card to activate.")++ class Meta:+ description = "Activate a gift card."+ permissions = ("giftcard.manage_gift_card",)++ @classmethod+ def perform_mutation(cls, _root, info, **data):+ gift_card_id = data.get("id")+ gift_card = cls.get_node_or_error(+ info, gift_card_id, field="gift_card_id", only_type=GiftCard+ )+ if not gift_card.is_active:+ gift_card.is_active = True+ gift_card.save(update_fields=["is_active"])return GiftCardDeactivate(gift_card=gift_card)diff --git a/saleor/graphql/giftcard/schema.py b/saleor/graphql/giftcard/schema.pyindex ec66a05c96..22f978181e 100644--- a/saleor/graphql/giftcard/schema.py+++ b/saleor/graphql/giftcard/schema.py@@ -4,6 +4,7 @@ from graphql_jwt.decorators import permission_requiredfrom ...giftcard import modelsfrom ..core.fields import PrefetchingConnectionFieldfrom .mutations import (+ GiftCardActivate,GiftCardCreate,GiftCardDeactivate,GiftCardUpdate,@@ -30,7 +31,8 @@ class GiftCardQueries(graphene.ObjectType):class GiftCardMutations(graphene.ObjectType):+ gift_card_activate = GiftCardActivate.Field()gift_card_create = GiftCardCreate.Field()- gift_card_update = GiftCardUpdate.Field()gift_card_deactivate = GiftCardDeactivate.Field()+ gift_card_update = GiftCardUpdate.Field()gift_card_verify = GiftCardVerify.Field()