Added voucher redemption

This commit is contained in:
Raphael Michel
2016-02-11 16:41:22 +01:00
parent bcde964ea3
commit f18a180ae4
15 changed files with 226 additions and 66 deletions

View File

@@ -7,6 +7,9 @@
{% if line.variation %}
{{ line.variation }}
{% endif %}
{% if line.voucher %}
<br /><span class="fa fa-ticket"></span> {% trans "Voucher code used:" %} {{ line.voucher.code }}
{% endif %}
{% if line.has_questions %}
<dl>
{% if line.item.admission and event.settings.attendee_names_asked%}

View File

@@ -6,32 +6,32 @@
{% block content %}
{% if cart.positions %}
<div class="panel panel-primary cart">
<div class="panel-heading">
<h3 class="panel-title">{% trans "Your cart" %}</h3>
</div>
<div class="panel-body">
{% include "pretixpresale/event/fragment_cart.html" with cart=cart event=request.event editable=True %}
<div class="row-fluid">
<div class="col-md-6 col-xs-12">
{% if cart.minutes_left > 0 %}
<em>{% blocktrans trimmed with minutes=cart.minutes_left %}
The items in your cart are reserved for you for {{ minutes }} minutes.
{% endblocktrans %}</em>
{% else %}
<em>{% trans "The items in your cart are no longer reserved for you." %}</em>
{% endif %}
<div class="panel panel-primary cart">
<div class="panel-heading">
<h3 class="panel-title">{% trans "Your cart" %}</h3>
</div>
<div class="panel-body">
{% include "pretixpresale/event/fragment_cart.html" with cart=cart event=request.event editable=True %}
<div class="row-fluid">
<div class="col-md-6 col-xs-12">
{% if cart.minutes_left > 0 %}
<em>{% blocktrans trimmed with minutes=cart.minutes_left %}
The items in your cart are reserved for you for {{ minutes }} minutes.
{% endblocktrans %}</em>
{% else %}
<em>{% trans "The items in your cart are no longer reserved for you." %}</em>
{% endif %}
</div>
<div class="col-md-4 col-md-offset-2 col-xs-12">
<a class="btn btn-block btn-primary btn-lg"
href="{% eventurl request.event "presale:event.checkout.start" %}">
<i class="fa fa-shopping-cart"></i> {% trans "Proceed with checkout" %}
</a>
</div>
<div class="clearfix"></div>
</div>
<div class="col-md-4 col-md-offset-2 col-xs-12">
<a class="btn btn-block btn-primary btn-lg"
href="{% eventurl request.event "presale:event.checkout.start" %}">
<i class="fa fa-shopping-cart"></i> {% trans "Proceed with checkout" %}
</a>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
{% endif %}
{% if not event.presale_is_running %}
<div class="alert alert-info">
@@ -67,7 +67,7 @@
data-title="{{ item.name }}"
data-lightbox="{{ item.id }}">
<img src="{{ item.picture|thumbnail_url:'productlist' }}"
alt="{{ item.name }}" />
alt="{{ item.name }}"/>
</a>
{% endif %}
<a href="javascript:void(0);" data-toggle="variations">
@@ -100,7 +100,8 @@
<div class="col-md-2 col-xs-6 price">
{{ event.currency }} {{ var.price|floatformat:2 }}
{% if item.tax_rate %}
<br /><small>{% blocktrans trimmed with rate=item.tax_rate %}
<br/>
<small>{% blocktrans trimmed with rate=item.tax_rate %}
incl. {{ rate }}% taxes
{% endblocktrans %}</small>
{% endif %}
@@ -127,7 +128,7 @@
data-title="{{ item.name }}"
data-lightbox="{{ item.id }}">
<img src="{{ item.picture|thumbnail_url:'productlist' }}"
alt="{{ item.name }}" />
alt="{{ item.name }}"/>
</a>
{% endif %}
<strong>{{ item.name }}</strong>
@@ -136,9 +137,10 @@
<div class="col-md-2 col-xs-6 price">
{{ event.currency }} {{ item.price|floatformat:2 }}
{% if item.tax_rate %}
<br /><small>{% blocktrans trimmed with rate=item.tax_rate %}
incl. {{ rate }}% taxes
{% endblocktrans %}</small>
<br/>
<small>{% blocktrans trimmed with rate=item.tax_rate %}
incl. {{ rate }}% taxes
{% endblocktrans %}</small>
{% endif %}
</div>
{% if item.cached_availability.0 == 100 %}
@@ -156,8 +158,29 @@
</section>
{% endfor %}
{% if event.presale_is_running %}
{% if vouchers_exist %}
<div class="row-fluid voucher-row">
<div class="col-md-4 col-md-offset-8 col-xs-12">
<div id="voucher-box">
<label for="voucher">{% trans "Redeem a voucher" %}</label>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-ticket fa-fw"></i></span>
<input type="text" class="form-control" name="voucher" id="voucher"
placeholder="{% trans "Voucher code" %}">
</div>
</div>
<div id="voucher-toggle">
<a href="javascript:void(0);">
<span class="fa fa-ticket"></span> Redeem a voucher
</a>
</div>
</div>
<div class="clearfix"></div>
</div>
{% endif %}
<div class="row-fluid checkout-button-row">
<div class="col-md-4 col-md-offset-8">
<div class="col-md-4 col-md-offset-8 col-xs-12">
<button class="btn btn-block btn-primary btn-lg" type="submit">
<i class="fa fa-shopping-cart"></i> {% trans "Add to cart" %}
</button>

View File

@@ -48,8 +48,8 @@ class CartMixin:
def keyfunc(pos):
if answers and ((pos.item.admission and self.request.event.settings.attendee_names_asked)
or pos.item.questions.all()):
return pos.id, 0, 0, 0
return 0, pos.item_id, pos.variation_id, pos.price
return pos.id, 0, 0, 0, None
return 0, pos.item_id, pos.variation_id, pos.price, pos.voucher
positions = []
for k, g in groupby(sorted(list(cartpos), key=keyfunc), key=keyfunc):

View File

@@ -26,7 +26,7 @@ class CartActionMixin:
def get_error_url(self):
return self.get_next_url()
def _items_from_post_data(self):
def _items_from_post_data(self, warn=True):
"""
Parses the POST data and returns a list of tuples in the
form (item id, variation id or None, number)
@@ -47,7 +47,7 @@ class CartActionMixin:
except ValueError:
messages.error(self.request, _('Please enter numbers only.'))
return []
if len(items) == 0:
if len(items) == 0 and warn:
messages.warning(self.request, _('You did not select any products.'))
return []
return items
@@ -93,9 +93,11 @@ class CartAdd(EventViewMixin, CartActionMixin, AsyncAction, View):
return super().get_error_message(exception)
def post(self, request, *args, **kwargs):
items = self._items_from_post_data()
if items:
return self.do(self.request.event.id, items, self.request.session.session_key)
voucher = self.request.POST.get('voucher')
items = self._items_from_post_data(warn=not voucher)
if items or voucher:
return self.do(self.request.event.id, items, self.request.session.session_key,
voucher)
else:
if 'ajax' in self.request.GET or 'ajax' in self.request.POST:
return JsonResponse({

View File

@@ -60,5 +60,11 @@ class EventIndex(EventViewMixin, CartMixin, TemplateView):
group[0] is not None and group[0].id is not None) else (0, 0)
)
vouchers_exist = self.request.event.get_cache().get('vouchers_exist')
if vouchers_exist is None:
vouchers_exist = self.request.event.vouchers.exists()
self.request.event.get_cache().set('vouchers_exist', vouchers_exist)
context['vouchers_exist'] = vouchers_exist
context['cart'] = self.get_cart()
return context