mirror of
https://github.com/pretix/pretix.git
synced 2026-05-06 15:24:02 +00:00
* Hide add to cart button if no products active or no quantity left(#180) * Fix PEP errors and improve logic * Fix tests for add to cart change * Fix the logic for toggling the visibility of Add to Cart button
This commit is contained in:
committed by
Raphael Michel
parent
6108aa880a
commit
5346473f75
@@ -202,7 +202,7 @@
|
||||
{% endfor %}
|
||||
</section>
|
||||
{% endfor %}
|
||||
{% if event.presale_is_running %}
|
||||
{% if event.presale_is_running and display_add_to_cart %}
|
||||
<div class="row-fluid checkout-button-row">
|
||||
<div class="col-md-4 col-md-offset-8 col-xs-12">
|
||||
<button class="btn btn-block btn-primary btn-lg" type="submit">
|
||||
|
||||
@@ -39,7 +39,7 @@ class EventIndex(EventViewMixin, CartMixin, TemplateView):
|
||||
).annotate(quotac=Count('quotas')).filter(
|
||||
quotac__gt=0
|
||||
).order_by('category__position', 'category_id', 'position', 'name')
|
||||
|
||||
display_add_to_cart = False
|
||||
for item in items:
|
||||
item.available_variations = list(item.variations.filter(active=True, quotas__isnull=False).distinct())
|
||||
item.has_variations = item.variations.exists()
|
||||
@@ -49,12 +49,14 @@ class EventIndex(EventViewMixin, CartMixin, TemplateView):
|
||||
if item.cached_availability[1] is not None else sys.maxsize,
|
||||
int(self.request.event.settings.max_items_per_order))
|
||||
item.price = item.default_price
|
||||
display_add_to_cart = display_add_to_cart or item.order_max > 0
|
||||
else:
|
||||
for var in item.available_variations:
|
||||
var.cached_availability = list(var.check_quotas())
|
||||
var.order_max = min(var.cached_availability[1]
|
||||
if var.cached_availability[1] is not None else sys.maxsize,
|
||||
int(self.request.event.settings.max_items_per_order))
|
||||
display_add_to_cart = display_add_to_cart or var.order_max > 0
|
||||
var.price = var.default_price if var.default_price is not None else item.default_price
|
||||
if len(item.available_variations) > 0:
|
||||
item.min_price = min([v.price for v in item.available_variations])
|
||||
@@ -64,6 +66,7 @@ class EventIndex(EventViewMixin, CartMixin, TemplateView):
|
||||
|
||||
# Regroup those by category
|
||||
context['items_by_category'] = item_group_by_category(items)
|
||||
context['display_add_to_cart'] = display_add_to_cart
|
||||
|
||||
vouchers_exist = self.request.event.get_cache().get('vouchers_exist')
|
||||
if vouchers_exist is None:
|
||||
|
||||
Reference in New Issue
Block a user