Skip to content

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

Improve voucher form

Patryk Zawadzki644602965a62
diff --git a/saleor/checkout/templates/checkout/details.html b/saleor/checkout/templates/checkout/details.html
index 6aff0a64ea..9aa670458b 100644
--- a/saleor/checkout/templates/checkout/details.html
+++ b/saleor/checkout/templates/checkout/details.html
@@ -119,21 +119,33 @@
{% endfor %}
{% if voucher_form %}
- <div class="panel panel-default">
- <div class="panel-heading">{% trans "Discount" %}</div>
- <div class="panel-body">
- {% if voucher %}
- {{ voucher }}
- {% else %}
- <form action="{% url "checkout:add-voucher" %}?next={{ request.get_full_path }}"
- method="post" class="form-inline">
- {% csrf_token %}
- {% bootstrap_form voucher_form layout='inline' %}
- {% bootstrap_button _("Apply") button_type="submit" button_class="btn-default" %}
- </form>
- {% endif %}
- </div>
- </div>
+ {% if voucher %}
+ <form action="{% url "checkout:remove-voucher" %}?next={{ request.get_full_path }}"
+ method="post" class="form">
+ {% csrf_token %}
+ <div class="row">
+ <div class="col-sm-8">
+ <strong>{{ voucher }}</strong>
+ </div>
+ <div class="col-sm-4">
+ {% bootstrap_button _("Remove") button_type="submit" button_class="btn-block btn-danger" %}
+ </div>
+ </div>
+ </form>
+ {% else %}
+ <form action="{% url "checkout:add-voucher" %}?next={{ request.get_full_path }}"
+ method="post" class="form">
+ {% csrf_token %}
+ <div class="row">
+ <div class="col-sm-8">
+ {% bootstrap_form voucher_form show_label=False %}
+ </div>
+ <div class="col-sm-4">
+ {% bootstrap_button _("Apply") button_type="submit" button_class="btn-block btn-default" %}
+ </div>
+ </div>
+ </form>
+ {% endif %}
{% endif %}
{% with total=checkout.get_total %}
diff --git a/saleor/checkout/views/discount.py b/saleor/checkout/views/discount.py
index 05f76dfd52..4337db0d80 100644
--- a/saleor/checkout/views/discount.py
+++ b/saleor/checkout/views/discount.py
@@ -10,7 +10,7 @@ def add_voucher_form(view):
voucher = None
initial = {'voucher': voucher}
voucher_form = GetVoucherForm(
- request.POST or None, prefix='discount', initial=initial)
+ None, prefix='discount', initial=initial)
template_response = view(request, checkout)
template_response.context_data['voucher_form'] = voucher_form
template_response.context_data['voucher'] = voucher
@@ -24,4 +24,3 @@ def apply_voucher_view(request, checkout):
if voucher_form.is_valid():
voucher = voucher_form.cleaned_data['voucher']
return redirect(next_url)
-
diff --git a/saleor/discount/forms.py b/saleor/discount/forms.py
index 798ac87dc3..c448e08b37 100644
--- a/saleor/discount/forms.py
+++ b/saleor/discount/forms.py
@@ -8,6 +8,5 @@ class GetVoucherForm(forms.Form):
voucher = forms.ModelChoiceField(
queryset=Voucher.objects.all(), to_field_name='code',
- label=pgettext_lazy('voucher_form', 'code'),
+ label=pgettext_lazy('voucher', 'Voucher code'),
widget=forms.TextInput)
-