Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Drop assigning cheapest shipping method in checkout
Marcin Gębala902ac81e51cf
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 68b21f7313..c5a33db01e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -129,6 +129,7 @@ All notable, unreleased changes to this project will be documented in this file.- Add app support for events - #7622 by @IKarbowiak- Add date & date time attributes - #7500 by @piotrgrundas- Add `withChoices` flag for Attribute type - #7733 by @dexon44+- Drop assigning cheapest shipping method in checkout - #7767 by @maarcingebala### Breaking- Multichannel MVP: Multicurrency - #6242 by @fowczarek @d-wysockidiff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex dbccc3c58c..afe57a960b 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -15,7 +15,6 @@ from ...checkout.fetch import (fetch_checkout_info,fetch_checkout_lines,get_valid_shipping_method_list_for_checkout_info,- update_checkout_info_shipping_method,)from ...checkout.utils import (add_promo_code_to_checkout,@@ -23,6 +22,7 @@ from ...checkout.utils import (calculate_checkout_quantity,change_billing_address_in_checkout,change_shipping_address_in_checkout,+ clear_shipping_method,is_shipping_required,recalculate_checkout_discount,remove_promo_code_from_checkout,@@ -93,14 +93,11 @@ def clean_shipping_method(def update_checkout_shipping_method_if_invalid(checkout_info: "CheckoutInfo", lines: Iterable[CheckoutLineInfo]):- checkout = checkout_info.checkoutquantity = calculate_checkout_quantity(lines)+# remove shipping method when empty checkoutif quantity == 0 or not is_shipping_required(lines):- checkout.shipping_method = None- checkout_info.shipping_method = None- checkout_info.shipping_method_channel_listings = None- checkout.save(update_fields=["shipping_method", "last_change"])+ clear_shipping_method(checkout_info)is_valid = clean_shipping_method(checkout_info=checkout_info,@@ -109,11 +106,8 @@ def update_checkout_shipping_method_if_invalid()if not is_valid:- cheapest_alternative = checkout_info.valid_shipping_methods- new_shipping_method = cheapest_alternative[0] if cheapest_alternative else None- checkout.shipping_method = new_shipping_method- update_checkout_info_shipping_method(checkout_info, new_shipping_method)- checkout.save(update_fields=["shipping_method", "last_change"])+ # remove shipping method when it is no longer valid+ clear_shipping_method(checkout_info)def check_lines_quantity(diff --git a/saleor/graphql/checkout/tests/test_checkout.py b/saleor/graphql/checkout/tests/test_checkout.pyindex 68e5e5bc45..9ab3b45535 100644--- a/saleor/graphql/checkout/tests/test_checkout.py+++ b/saleor/graphql/checkout/tests/test_checkout.py@@ -78,7 +78,7 @@ def test_update_checkout_shipping_method_if_invalid(other_shipping_method,shipping_zone_without_countries,):- """If the shipping method is invalid, it should replace it."""+ # If the shipping method is invalid, it should be removed.checkout = checkout_with_single_itemcheckout.shipping_address = address@@ -92,18 +92,13 @@ def test_update_checkout_shipping_method_if_invalid(checkout_info = fetch_checkout_info(checkout, lines, [], manager)update_checkout_shipping_method_if_invalid(checkout_info, lines)- assert checkout.shipping_method == other_shipping_method- assert checkout_info.shipping_method == other_shipping_method- assert (- checkout_info.shipping_method_channel_listings- == shipping_models.ShippingMethodChannelListing.objects.filter(- shipping_method=other_shipping_method, channel=checkout_info.channel- ).first()- )+ assert checkout.shipping_method is None+ assert checkout_info.shipping_method is None+ assert checkout_info.shipping_method_channel_listings is None# Ensure the checkout's shipping method was savedcheckout.refresh_from_db(fields=["shipping_method"])- assert checkout.shipping_method == other_shipping_method+ assert checkout.shipping_method is NoneMUTATION_CHECKOUT_CREATE = """diff --git a/saleor/graphql/checkout/tests/test_checkout_promo_codes.py b/saleor/graphql/checkout/tests/test_checkout_promo_codes.pyindex 64d28a72be..f279b61c9a 100644--- a/saleor/graphql/checkout/tests/test_checkout_promo_codes.py+++ b/saleor/graphql/checkout/tests/test_checkout_promo_codes.py@@ -712,7 +712,7 @@ def test_checkout_add_promo_code_invalidate_shipping_method(shipping_method_id = graphene.Node.to_global_id("ShippingMethod", shipping_method.pk)- assert shipping_method_id != data["checkout"]["shippingMethod"]["id"]+ assert data["checkout"]["shippingMethod"] is Noneassert shipping_method_id not in data["checkout"]["availableShippingMethods"]