Skip to content

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

Use min() to determine cheapest shipping

Patryk Zawadzki3eb0a37e9312
diff --git a/saleor/checkout/steps.py b/saleor/checkout/steps.py
index 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 itemgetter
from django.core.exceptions import ValidationError
from 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 = shipping
else:
+ cheapest_shipping = min(available_shipping,
+ key=itemgetter('cost'))
selected_method_name = cheapest_shipping['method'].name
self.available_shipping = available_shipping
shipping_form = ShippingForm(shipping_choices, request.POST or None,