Skip to content

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

Add functionality and styles for delivery information form

weronkaae58445dca22
diff --git a/saleor/cart/forms.py b/saleor/cart/forms.py
index 6b66c089b5..46de883f29 100644
--- a/saleor/cart/forms.py
+++ b/saleor/cart/forms.py
@@ -118,8 +118,7 @@ class ReplaceCartLineForm(AddToCartForm):
class CountryForm(forms.Form):
- country = forms.ChoiceField(choices=COUNTRY_CODE_CHOICES)
-
+ 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/static/js/demo/storefront.js b/saleor/static/js/demo/storefront.js
index 2fec20842d..69f789cb5f 100644
--- a/saleor/static/js/demo/storefront.js
+++ b/saleor/static/js/demo/storefront.js
@@ -92,3 +92,30 @@ $('.product-form button').click((e) => {
}
})
})
+
+// Delivery information
+
+var $deliveryForm = $('.deliveryform')
+var crsfToken = $deliveryForm.data('crsf')
+var $countrySelect = $('#id_country')
+var $newMethod = $('.cart__delivery-info__method')
+var $newPrice = $('.cart__delivery-info__price')
+$countrySelect.on('change', (e) => {
+ var newCountry = $countrySelect.val()
+ $.ajax({
+ url: "/cart/shipingoptions/",
+ type: 'POST',
+ data: {
+ 'csrfmiddlewaretoken': crsfToken,
+ 'country': newCountry
+ },
+ success: (data) => {
+ $newMethod.empty()
+ $newPrice.empty()
+ $.each(data.options, (key, val) => {
+ $newMethod.append('<p>' + val.shipping_method__name + '</p>')
+ $newPrice.append('<p>$' + val.price[1] + '</p>')
+ })
+ }
+ })
+})
diff --git a/saleor/static/scss/demo/components/_cart.scss b/saleor/static/scss/demo/components/_cart.scss
index 5ca06d49e0..7afd781534 100644
--- a/saleor/static/scss/demo/components/_cart.scss
+++ b/saleor/static/scss/demo/components/_cart.scss
@@ -53,11 +53,16 @@
border-bottom: 1px solid $gray;
padding-bottom: $global-padding
}
- .custom-select {
- max-width: 100%;
- display: inline-block;
+ select {
color: $body-color;
margin-left: $global-margin / 2;
+ background-color: $white;
+ &:focus {
+ outline: none;
+ }
+ }
+ &__price {
+ text-align: right;
}
}
&__empty {
diff --git a/templates/cart/index.html b/templates/cart/index.html
index 9344c35d5d..aa1ebd57d5 100644
--- a/templates/cart/index.html
+++ b/templates/cart/index.html
@@ -100,22 +100,24 @@
<a href="{% url "checkout:login" %}" class="btn primary float-md-right">{% trans "Checkout" %}</a>
</div>
</div>
- <div class="col-md-5 cart__delivery-info">
- <h3>{% trans "Delivery options to" %}
- <select class="custom-select">
- {% for country in country_choices %}
- <option>{{ country }}</option>
- {% endfor %}
- </select>
- </h3>
- <div class="row">
- <div class="col-md-6">
- <p>DHL to Poland</p>
+ <div class="cart__delivery-info">
+ <div class="deliveryform" data-csrf="{{ csrf_token }}">
+ <h3>{% trans "Delivery options to" %} {{ country_form }}</h3>
+ </div>
+ <div class="col-md-5 ">
+ <div class="cart__delivery-list row">
+ <div class="col-md-6 cart__delivery-info__method">
+ {% for option in default_country_options %}
+ <p>{{ option.shipping_method__name }}</p>
+ {% endfor %}
</div>
- <div class="col-md-6">
- <p class="float-xs-right">$10</p>
+ <div class="col-md-6 cart__delivery-info__price">
+ {% for option in default_country_options %}
+ <p>{% gross option.price %}</p>
+ {% endfor %}
</div>
</div>
+ </div>
</div>
{% else %}
<div class="cart__empty">