Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Set default country prefix based on country code
akjanik989821d9229e
diff --git a/saleor/checkout/views/shipping.py b/saleor/checkout/views/shipping.pyindex 8d14f450b4..b392a27751 100644--- a/saleor/checkout/views/shipping.py+++ b/saleor/checkout/views/shipping.py@@ -35,7 +35,6 @@ def user_shipping_address_view(request, checkout):In addition to entering a new address the user has an option of selectingone of the existing entries from their address book."""- # import ipdb; ipdb.set_trace()data = request.POST or Noneadditional_addresses = request.user.addresses.all()checkout.email = request.user.emaildiff --git a/saleor/userprofile/forms.py b/saleor/userprofile/forms.pyindex ae63fcb4f9..0504988091 100644--- a/saleor/userprofile/forms.py+++ b/saleor/userprofile/forms.py@@ -15,6 +15,10 @@ def get_address_form(data, country_code, initial=None, instance=None, **kwargs):if country_form.is_valid():country_code = country_form.cleaned_data['country']preview = country_form.cleaned_data['preview']+ if initial is None and country_code:+ initial = {}+ initial['phone'] = '+{}'.format(+ country_code_for_region(country_code))address_form_class = get_address_form_class(country_code)diff --git a/saleor/userprofile/i18n.py b/saleor/userprofile/i18n.pyindex 9e5cdc77b4..7a7d85e12b 100644--- a/saleor/userprofile/i18n.py+++ b/saleor/userprofile/i18n.py@@ -8,7 +8,8 @@ from django.forms.forms import BoundFieldfrom django.forms import Select, TextInputfrom django_countries.data import COUNTRIESfrom django.utils.translation import pgettext_lazy-from phonenumber_field.widgets import PhoneNumberPrefixWidget+from phonenumber_field.widgets import (+ PhoneNumberPrefixWidget, PhonePrefixSelect)from phonenumber_field.formfields import PhoneNumberFieldfrom phonenumbers import COUNTRY_CODE_TO_REGION_CODE@@ -48,6 +49,17 @@ AREA_TYPE_TRANSLATIONS = {'zip': pgettext_lazy('Address field', 'ZIP code')}+class CustomPhonePrefix(PhonePrefixSelect):++ def __init__(self, initial=None):+ choices = phone_prefixes+ if initial:+ self.initial = phone_prefixes[initial]++ super(PhonePrefixSelect, self).__init__(+ choices=sorted(choices, key=lambda item: item[1]))++class PhonePrefixWidget(PhoneNumberPrefixWidget):def __init__(self, attrs=None):widgets = (Select(attrs=attrs, choices=phone_prefixes), TextInput())