Skip to content

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

Fix no longer available external shipping (#9048)

Filip Owczarek08e2b4ccb68b
diff --git a/saleor/checkout/fetch.py b/saleor/checkout/fetch.py
index 8f97d01e40..42a8f94e0f 100644
--- a/saleor/checkout/fetch.py
+++ b/saleor/checkout/fetch.py
@@ -181,10 +181,10 @@ def get_delivery_method_info(
delivery_method: Optional[Union["ShippingMethodData", "Warehouse", Callable]],
address=Optional["Address"],
) -> DeliveryMethodBase:
- if delivery_method is None:
- return DeliveryMethodBase()
if callable(delivery_method):
delivery_method = delivery_method()
+ if delivery_method is None:
+ return DeliveryMethodBase()
if isinstance(delivery_method, ShippingMethodData):
return ShippingMethodInfo(delivery_method, address)
if isinstance(delivery_method, Warehouse):
diff --git a/saleor/checkout/tests/test_checkout.py b/saleor/checkout/tests/test_checkout.py
index 92b4be3019..a97eb3a31f 100644
--- a/saleor/checkout/tests/test_checkout.py
+++ b/saleor/checkout/tests/test_checkout.py
@@ -107,6 +107,36 @@ def test_is_valid_delivery_method_external_method(
assert delivery_method_info.is_method_in_valid_methods(checkout_info)
+@patch("saleor.plugins.webhook.tasks.send_webhook_request_sync")
+def test_is_valid_delivery_method_external_method_no_longer_available(
+ mock_send_request, checkout_with_item, address, settings, shipping_app
+):
+ settings.PLUGINS = ["saleor.plugins.webhook.plugin.WebhookPlugin"]
+ mock_json_response = [
+ {
+ "id": "New-ID",
+ "name": "Provider - Economy",
+ "amount": "10",
+ "currency": "USD",
+ "maximum_delivery_days": "7",
+ }
+ ]
+ method_id = graphene.Node.to_global_id("app", f"{shipping_app.id}:1")
+
+ mock_send_request.return_value = mock_json_response
+ checkout = checkout_with_item
+ checkout.shipping_address = address
+ checkout.private_metadata = {PRIVATE_META_APP_SHIPPING_ID: method_id}
+ checkout.save()
+
+ manager = get_plugins_manager()
+ lines = fetch_checkout_lines(checkout)
+ checkout_info = fetch_checkout_info(checkout, lines, [], manager)
+ delivery_method_info = checkout_info.delivery_method_info
+
+ assert delivery_method_info.is_method_in_valid_methods(checkout_info) is False
+
+
def test_clear_delivery_method(checkout, shipping_method):
checkout.shipping_method = shipping_method
checkout.save()