Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add function for selecting delivery options
Mira Szewczyk7283ad8970d7
diff --git a/saleor/cart/forms.py b/saleor/cart/forms.pyindex 644e2def1c..2ada2fbff6 100644--- a/saleor/cart/forms.py+++ b/saleor/cart/forms.py@@ -4,7 +4,7 @@ from django import formsfrom django.core.exceptions import ObjectDoesNotExist, NON_FIELD_ERRORSfrom django.utils.translation import pgettext_lazy, ugettext_lazyfrom satchless.item import InsufficientStock-from ..shipping.models import COUNTRY_CODE_CHOICES+from ..shipping.models import COUNTRY_CODE_CHOICES, ShippingMethodCountryclass 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.pyindex 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',{