Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix address form, add UI
Patryk Zawadzkicee66c1bd140
diff --git a/saleor/static/js/storefront.js b/saleor/static/js/storefront.jsindex c7e151399b..82a25d19ed 100644--- a/saleor/static/js/storefront.js+++ b/saleor/static/js/storefront.js@@ -39,3 +39,16 @@ $(function() {$img.attr('src', dataSrc)})})++$(function() {+ const $i18nAddresses = $('.i18n-address')+ $i18nAddresses.each(function () {+ const $form = $(this).closest('form')+ const $countryField = $form.find('select[name=country]')+ const $previewField = $form.find('input.preview')+ $countryField.on('change', () => {+ $previewField.val('on')+ $form.submit()+ })+ })+})diff --git a/saleor/static/scss/storefront.scss b/saleor/static/scss/storefront.scssindex f1a08493ac..71e46d654d 100644--- a/saleor/static/scss/storefront.scss+++ b/saleor/static/scss/storefront.scss@@ -31,6 +31,19 @@ $icon-font-path: "~bootstrap-sass/assets/fonts/bootstrap/";cursor: pointer;}+.i18n-address {+ .row {+ @media (min-width: $screen-sm-min) {+ display: flex;++ .col-sm-4 {+ float: none;+ flex: 1;+ }+ }+ }+}+.popover {min-width: 200px;}diff --git a/saleor/userprofile/i18n.py b/saleor/userprofile/i18n.pyindex c42d507321..eab50841bd 100644--- a/saleor/userprofile/i18n.py+++ b/saleor/userprofile/i18n.py@@ -125,7 +125,7 @@ class CountryAwareAddressForm(AddressForm):return datadef clean(self):- data = super(AddressForm, self).clean()+ data = super(CountryAwareAddressForm, self).clean()return self.validate_address(data)@@ -135,7 +135,11 @@ def get_address_form_class(country_code):def get_form_18n_lines(form_instance):country_code = form_instance.i18n_country_code- fields_order = i18naddress.get_field_order({'country_code': country_code})+ try:+ fields_order = i18naddress.get_field_order(+ {'country_code': country_code})+ except ValueError:+ fields_order = i18naddress.get_field_order({})field_mapping = dict(form_instance.I18N_MAPPING)def _convert_to_bound_fields(form, i18n_field_names):diff --git a/templates/checkout/shipping_address.html b/templates/checkout/shipping_address.htmlindex 7de0f80727..9c5abba67b 100644--- a/templates/checkout/shipping_address.html+++ b/templates/checkout/shipping_address.html@@ -32,7 +32,9 @@{% block forms %}<form method="post" novalidate>{% csrf_token %}- <h3>{% trans "Shipping address" %}</h3>+ <div class="page-header">+ <h3>{% trans "Shipping address" %}</h3>+ </div>{% if request.user.is_authenticated %}{% include "checkout/snippets/addresses-form.html" with addresses_form=user_form addresses=additional_addresses address_form=address_form only %}{% else %}diff --git a/templates/userprofile/snippets/address-form.html b/templates/userprofile/snippets/address-form.htmlindex 52c99a75c7..92f8fdeee2 100644--- a/templates/userprofile/snippets/address-form.html+++ b/templates/userprofile/snippets/address-form.html@@ -1,20 +1,22 @@{% load bootstrap_field from bootstrap3 %}-{% bootstrap_field address_form.phone %}-{% with address_form_lines=address_form.i18n_fields_order %}- {% if address_form_lines %}- {% for line in address_form_lines %}- <div class="row">- {% for field in line %}- <div class="col-sm-4">- {% bootstrap_field field %}- </div>- {% endfor %}- </div>- {% endfor %}- {% endif %}-{% endwith %}-{% for field in address_form.hidden_fields %}- {{ field }}-{% endfor %}-{% bootstrap_field address_form.country %}-<input type="checkbox" name="preview">+<div class="i18n-address">+ {% bootstrap_field address_form.phone %}+ {% with address_form_lines=address_form.i18n_fields_order %}+ {% if address_form_lines %}+ {% for line in address_form_lines %}+ <div class="row">+ {% for field in line %}+ <div class="col-sm-4">+ {% bootstrap_field field %}+ </div>+ {% endfor %}+ </div>+ {% endfor %}+ {% endif %}+ {% endwith %}+ {% for field in address_form.hidden_fields %}+ {{ field }}+ {% endfor %}+ {% bootstrap_field address_form.country %}+ <input type="hidden" class="preview" name="preview">+</div>