Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Use min() to determine cheapest shipping
Patryk Zawadzki3eb0a37e9312
diff --git a/saleor/checkout/steps.py b/saleor/checkout/steps.pyindex 38ad13ae7c..672666e1e2 100644--- a/saleor/checkout/steps.py+++ b/saleor/checkout/steps.py@@ -1,4 +1,5 @@from __future__ import unicode_literals+from operator import itemgetterfrom django.core.exceptions import ValidationErrorfrom django.db import models@@ -157,14 +158,13 @@ class ShippingMethodStep(BaseCheckoutStep):for shipping in available_shipping]if available_shipping:- cheapest_shipping = available_shipping[0]for shipping in available_shipping:if shipping['method'].name == selected_method_name:self.shipping_method = shipping['method']break- if shipping['cost'] < cheapest_shipping['cost']:- cheapest_shipping = shippingelse:+ cheapest_shipping = min(available_shipping,+ key=itemgetter('cost'))selected_method_name = cheapest_shipping['method'].nameself.available_shipping = available_shippingshipping_form = ShippingForm(shipping_choices, request.POST or None,