Skip to content

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

Check if shipping method is valid while creating the order

Pacu2d4851ee5fd21
diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.py
index cec62b95c0..19f1ba17ae 100644
--- a/saleor/checkout/utils.py
+++ b/saleor/checkout/utils.py
@@ -892,7 +892,8 @@ def is_fully_paid(cart: Cart):
return total_paid >= cart.get_total().gross.amount
-def ready_to_place_order(cart: Cart):
+def ready_to_place_order(cart: Cart, taxes, discounts):
+ #FIXME test me
if cart.is_shipping_required():
if not cart.shipping_method:
return False, pgettext_lazy(
@@ -900,7 +901,10 @@ def ready_to_place_order(cart: Cart):
if not cart.shipping_address:
return False, pgettext_lazy(
'order placement error', 'Shipping address is not set')
- # FIXME Check if shipping method is valid for the shipping address
+ if not is_valid_shipping_method(cart, taxes, discounts):
+ return False, pgettext_lazy(
+ 'order placement error',
+ 'Shipping method is not valid for your shipping address')
if not is_fully_paid(cart):
return False, pgettext_lazy(
'order placement error', 'Checkout is not fully paid')
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.py
index 1caad58b19..355b92153f 100644
--- a/saleor/graphql/checkout/mutations.py
+++ b/saleor/graphql/checkout/mutations.py
@@ -405,7 +405,9 @@ class CheckoutComplete(BaseMutation):
info, checkout_id, errors, 'checkout_id', only_type=Checkout)
if not checkout:
return CheckoutComplete(errors=errors)
- ready, checkout_error = ready_to_place_order(checkout)
+ taxes = get_taxes_for_cart(checkout, info.context.taxes)
+ ready, checkout_error = ready_to_place_order(
+ checkout, taxes, info.context.discounts)
if not ready:
cls.add_error(field=None, message=checkout_error, errors=errors)
return CheckoutComplete(errors=errors)
@@ -415,7 +417,7 @@ class CheckoutComplete(BaseMutation):
cart=checkout,
tracking_code=analytics.get_client_id(info.context),
discounts=info.context.discounts,
- taxes=get_taxes_for_cart(checkout, info.context.taxes))
+ taxes=taxes)
except InsufficientStock:
order = None
cls.add_error(