Skip to content

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

Remove gift card from checkout in remove promo code mutation

fowczarekc60877bb3b51
diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.py
index 939383eed3..ea6165ad32 100644
--- a/saleor/checkout/utils.py
+++ b/saleor/checkout/utils.py
@@ -27,7 +27,10 @@ from ..discount.utils import (
get_value_voucher_discount,
increase_voucher_usage,
)
-from ..giftcard.utils import add_gift_card_code_to_checkout
+from ..giftcard.utils import (
+ add_gift_card_code_to_checkout,
+ remove_gift_card_code_from_checkout,
+)
from ..order import events
from ..order.emails import send_order_confirmation
from ..order.models import Order
@@ -830,7 +833,7 @@ def remove_promo_code_from_checkout(checkout, promo_code):
if promo_code_is_voucher(promo_code):
remove_voucher_code_from_checkout(checkout, promo_code)
elif promo_code_is_gift_card(promo_code):
- raise ValidationError({"promo_code": "NOT IMPLEMENTED YET."})
+ remove_gift_card_code_from_checkout(checkout, promo_code)
def remove_voucher_code_from_checkout(checkout, promo_code):
diff --git a/saleor/giftcard/utils.py b/saleor/giftcard/utils.py
index 1223092900..be9aebe478 100644
--- a/saleor/giftcard/utils.py
+++ b/saleor/giftcard/utils.py
@@ -13,3 +13,9 @@ def add_gift_card_code_to_checkout(checkout, promo_code):
def add_gift_card_to_checkout(checkout, gift_card):
checkout.gift_cards.add(gift_card)
+
+
+def remove_gift_card_code_from_checkout(checkout, promo_code):
+ gift_card = checkout.gift_cards.filter(code=promo_code).first()
+ if gift_card:
+ checkout.gift_cards.remove(gift_card)