Skip to content

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

Raise a ValdiationError in CheckoutDeliveryMethodUpdate when shipping method has not channel listing (#10801)

Iga Karbowiak8a4924ad57c6
diff --git a/saleor/graphql/checkout/mutations/checkout_delivery_method_update.py b/saleor/graphql/checkout/mutations/checkout_delivery_method_update.py
index a5228e84f5..b5dd5b06bd 100644
--- a/saleor/graphql/checkout/mutations/checkout_delivery_method_update.py
+++ b/saleor/graphql/checkout/mutations/checkout_delivery_method_update.py
@@ -86,6 +86,16 @@ class CheckoutDeliveryMethodUpdate(BaseMutation):
channel=checkout_info.channel,
).first(),
)
+ if shipping_method and not delivery_method:
+ raise ValidationError(
+ {
+ "delivery_method_id": ValidationError(
+ "This shipping method is not applicable in the given channel.",
+ code=CheckoutErrorCode.DELIVERY_METHOD_NOT_APPLICABLE.value,
+ )
+ }
+ )
+
cls._check_delivery_method(
checkout_info, lines, shipping_method=delivery_method, collection_point=None
)
diff --git a/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py b/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py
index cf218d861d..89e1d83d2b 100644
--- a/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py
+++ b/saleor/graphql/checkout/tests/mutations/test_checkout_delivery_method_update.py
@@ -318,6 +318,7 @@ def test_checkout_delivery_method_update_shipping_zone_without_channel(
address,
):
shipping_method.shipping_zone.channels.clear()
+ shipping_method.channel_listings.all().delete()
checkout = checkout_with_item
checkout.shipping_address = address
checkout.save(update_fields=["shipping_address"])