Skip to content

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

Change logic of filtering shipping methods

Mira Szewczykd81a26b8fa0c
diff --git a/saleor/cart/forms.py b/saleor/cart/forms.py
index 46de883f29..9a58399af3 100644
--- a/saleor/cart/forms.py
+++ b/saleor/cart/forms.py
@@ -118,7 +118,9 @@ class ReplaceCartLineForm(AddToCartForm):
class CountryForm(forms.Form):
+
country = forms.ChoiceField(choices=COUNTRY_CODE_CHOICES, label='')
+
def get_shipment_options(self):
code = self.cleaned_data['country']
return get_shipment_options(code)
diff --git a/saleor/shipping/utils.py b/saleor/shipping/utils.py
index d4099f731b..45e0146ead 100644
--- a/saleor/shipping/utils.py
+++ b/saleor/shipping/utils.py
@@ -3,7 +3,9 @@ from .models import ShippingMethodCountry
def get_shipment_options(country_code):
- return ShippingMethodCountry.objects.select_related(
- 'shipping_method').filter(
- Q(country_code=country_code) | Q(country_code='')).order_by(
- 'price').values('price', 'shipping_method__name')
+ shipping_methods_qs = ShippingMethodCountry.objects.select_related(
+ 'shipping_method').values('price', 'shipping_method__name')
+ shipping_methods = shipping_methods_qs.filter(country_code=country_code)
+ if not shipping_methods.exists():
+ shipping_methods = shipping_methods_qs.filter(country_code='')
+ return shipping_methods