Skip to content

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

Add function for selecting delivery options

Mira Szewczyk7283ad8970d7
diff --git a/saleor/cart/forms.py b/saleor/cart/forms.py
index 644e2def1c..2ada2fbff6 100644
--- a/saleor/cart/forms.py
+++ b/saleor/cart/forms.py
@@ -4,7 +4,7 @@ from django import forms
from django.core.exceptions import ObjectDoesNotExist, NON_FIELD_ERRORS
from django.utils.translation import pgettext_lazy, ugettext_lazy
from satchless.item import InsufficientStock
-from ..shipping.models import COUNTRY_CODE_CHOICES
+from ..shipping.models import COUNTRY_CODE_CHOICES, ShippingMethodCountry
class QuantityField(forms.IntegerField):
@@ -117,3 +117,7 @@ class ReplaceCartLineForm(AddToCartForm):
class CountryForm(forms.Form):
country = forms.ChoiceField(choices=COUNTRY_CODE_CHOICES)
+
+ def get_shipment_options(self):
+ code = self.country
+ return ShippingMethodCountry.objects.filter(country_code=code)
diff --git a/saleor/cart/views.py b/saleor/cart/views.py
index 513b15cfe1..8cc6c6b232 100644
--- a/saleor/cart/views.py
+++ b/saleor/cart/views.py
@@ -40,6 +40,10 @@ def index(request, cart):
country_form = CountryForm(request.POST or None,
initial={'country': default_country})
+ if country_form.is_valid():
+ shipments = country_form.get_shipment_options()
+ return JsonResponse({'options': shipments})
+
return TemplateResponse(
request, 'cart/index.html',
{