From 4e59b02bb16261f411622d419b93effa2f14b7d0 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 20 Apr 2020 19:05:21 +0200 Subject: [PATCH] Re-label cart button if cart is not visible or all products are free --- .../pretixpresale/event/checkout_confirm.html | 1 + .../presale/templates/pretixpresale/event/index.html | 10 +++++++++- .../templates/pretixpresale/event/voucher.html | 10 +++++++++- src/pretix/presale/views/cart.py | 11 +++++++++++ src/pretix/presale/views/event.py | 10 ++++++++++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/pretix/presale/templates/pretixpresale/event/checkout_confirm.html b/src/pretix/presale/templates/pretixpresale/event/checkout_confirm.html index ab79842825..3467b54bed 100644 --- a/src/pretix/presale/templates/pretixpresale/event/checkout_confirm.html +++ b/src/pretix/presale/templates/pretixpresale/event/checkout_confirm.html @@ -189,6 +189,7 @@
diff --git a/src/pretix/presale/templates/pretixpresale/event/voucher.html b/src/pretix/presale/templates/pretixpresale/event/voucher.html index f062e4fa91..a4e5040804 100644 --- a/src/pretix/presale/templates/pretixpresale/event/voucher.html +++ b/src/pretix/presale/templates/pretixpresale/event/voucher.html @@ -338,7 +338,15 @@
diff --git a/src/pretix/presale/views/cart.py b/src/pretix/presale/views/cart.py index dbcf5a8725..0e429c598c 100644 --- a/src/pretix/presale/views/cart.py +++ b/src/pretix/presale/views/cart.py @@ -1,6 +1,7 @@ import json import mimetypes import os +from decimal import Decimal from django.conf import settings from django.contrib import messages @@ -455,6 +456,16 @@ class RedeemView(NoSearchIndexViewMixin, EventViewMixin, TemplateView): context['options'] = sum([(len(item.available_variations) if item.has_variations else 1) for item in items]) + context['allfree'] = all( + item.display_price.gross == Decimal('0.00') for item in items if not item.has_variations + ) and all( + all( + var.display_price.gross == Decimal('0.00') + for var in item.available_variations + ) + for item in items if item.has_variations + ) + # Regroup those by category context['items_by_category'] = item_group_by_category(items) diff --git a/src/pretix/presale/views/event.py b/src/pretix/presale/views/event.py index 104f93153c..4202cc4cf5 100644 --- a/src/pretix/presale/views/event.py +++ b/src/pretix/presale/views/event.py @@ -2,6 +2,7 @@ import calendar import sys from collections import defaultdict from datetime import date, datetime, timedelta +from decimal import Decimal from importlib import import_module import pytz @@ -319,6 +320,15 @@ class EventIndex(EventViewMixin, EventListMixin, CartMixin, TemplateView): items, display_add_to_cart = get_grouped_items(self.request.event, self.subevent, channel=self.request.sales_channel.identifier) context['itemnum'] = len(items) + context['allfree'] = all( + item.display_price.gross == Decimal('0.00') for item in items if not item.has_variations + ) and all( + all( + var.display_price.gross == Decimal('0.00') + for var in item.available_variations + ) + for item in items if item.has_variations + ) # Regroup those by category context['items_by_category'] = item_group_by_category(items)