Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Include discounts when resolving checkout shipping methods (#8768)
Iga Karbowiak1c45037b6565
diff --git a/saleor/graphql/checkout/tests/test_checkout.py b/saleor/graphql/checkout/tests/test_checkout.pyindex c6eb0d3bfb..c94c82ed32 100644--- a/saleor/graphql/checkout/tests/test_checkout.py+++ b/saleor/graphql/checkout/tests/test_checkout.py@@ -1663,6 +1663,48 @@ def test_checkout_available_shipping_methods_weight_method_with_higher_minimal_wassert shipping_method.name not in shipping_methods+def test_checkout_shipping_methods_with_price_based_shipping_method_and_discount(+ api_client,+ checkout_with_item,+ address,+ shipping_method,+):+ """Ensure that price based shipping method is not returned when+ checkout with discounts subtotal is lower than minimal order price."""+ checkout_with_item.shipping_address = address+ manager = get_plugins_manager()+ lines = fetch_checkout_lines(checkout_with_item)+ checkout_info = fetch_checkout_info(checkout_with_item, lines, [], manager)++ subtotal = calculations.checkout_subtotal(+ manager=manager,+ checkout_info=checkout_info,+ lines=lines,+ address=checkout_with_item.shipping_address,+ )++ checkout_with_item.discount_amount = Decimal(5.0)+ checkout_with_item.save(update_fields=["shipping_address", "discount_amount"])++ shipping_method.name = "Price based"+ shipping_method.save(update_fields=["name"])++ shipping_channel_listing = shipping_method.channel_listings.get(+ channel=checkout_with_item.channel+ )+ shipping_channel_listing.minimum_order_price_amount = subtotal.gross.amount - 1+ shipping_channel_listing.save(update_fields=["minimum_order_price_amount"])++ query = GET_CHECKOUT_AVAILABLE_SHIPPING_METHODS+ variables = {"token": checkout_with_item.token}+ response = api_client.post_graphql(query, variables)+ content = get_graphql_content(response)+ data = content["data"]["checkout"]++ shipping_methods = [method["name"] for method in data["availableShippingMethods"]]+ assert shipping_method.name not in shipping_methods++def test_checkout_available_shipping_methods_shipping_zone_without_channels(api_client, checkout_with_item, address, shipping_zone):diff --git a/saleor/graphql/checkout/types.py b/saleor/graphql/checkout/types.pyindex d63d40ee3f..b5cb5c7100 100644--- a/saleor/graphql/checkout/types.py+++ b/saleor/graphql/checkout/types.py@@ -452,6 +452,7 @@ class Checkout(CountableDjangoObjectType):subtotal = manager.calculate_checkout_subtotal(checkout_info, lines, address, discounts)+ subtotal -= checkout_info.checkout.discountif not address:return []available = get_valid_shipping_methods_for_checkout(