Show collapsed cart on voucher redemption page

This commit is contained in:
Raphael Michel
2021-04-17 13:46:29 +02:00
parent 3ea1a92716
commit 95d19dc656
4 changed files with 76 additions and 63 deletions

View File

@@ -0,0 +1,66 @@
{% load i18n %}
{% load eventurl %}
{% load safelink %}
{% load rich_text %}
{% load money %}
<details class="panel {% if open %}panel-primary{% else %}panel-default{% endif %} cart" {% if open %}open{% endif %}>
<summary class="panel-heading">
<h3 class="panel-title">
<span>
<i class="fa fa-shopping-cart" aria-hidden="true"></i>
<strong>{% trans "Your cart" %}</strong>
</span>
<span>
<strong id="cart-deadline-short" data-expires="{{ cart.first_expiry|date:"Y-m-d H:i:sO" }}" aria-hidden="true">
{% if cart.minutes_left > 0 or cart.seconds_left > 0 %}
{{ cart.minutes_left|stringformat:"02d" }}:{{ cart.seconds_left|stringformat:"02d" }}
{% else %}
{% trans "Cart expired" %}
{% endif %}
</strong>
<i class="fa fa-angle-down collapse-indicator" aria-hidden="true"></i>
</span>
</h3>
</summary>
<div>
<div class="panel-body">
{% include "pretixpresale/event/fragment_cart.html" with cart=cart event=request.event editable=True %}
<em id="cart-deadline" data-expires="{{ cart.first_expiry|date:"Y-m-d H:i:sO" }}">
{% if cart.minutes_left > 0 or cart.seconds_left > 0 %}
{% blocktrans trimmed with minutes=cart.minutes_left %}
The items in your cart are reserved for you for {{ minutes }} minutes.
{% endblocktrans %}
{% else %}
{% trans "The items in your cart are no longer reserved for you." %}
{% endif %}
</em>
<div class="row checkout-button-row">
<div class="col-md-4 col-sm-6 col-xs-12 hidden-xs">
<form method="post" data-asynctask action="{% eventurl request.event "presale:event.cart.clear" cart_namespace=cart_namespace %}">
{% csrf_token %}
<button class="btn btn-block btn-default btn-lg" type="submit">
<i class="fa fa-close" aria-hidden="true"></i> {% trans "Empty cart" %}</button>
</form>
</div>
<div class="col-md-4 col-sm-6 col-md-offset-4 col-xs-12">
<a class="btn btn-block btn-primary btn-lg"
href="{% eventurl request.event "presale:event.checkout.start" cart_namespace=cart_namespace %}">
{% if has_addon_choices or cart.total == 0 %}
<i class="fa fa-shopping-cart" aria-hidden="true"></i> {% trans "Continue" %}
{% else %}
<i class="fa fa-shopping-cart" aria-hidden="true"></i> {% trans "Proceed with checkout" %}
{% endif %}
</a>
</div>
<div class="visible-xs-block col-xs-12">
<form method="post" data-asynctask action="{% eventurl request.event "presale:event.cart.clear" cart_namespace=cart_namespace %}">
{% csrf_token %}
<button class="btn btn-block btn-default btn-lg" type="submit">
<i class="fa fa-close" aria-hidden="true"></i> {% trans "Empty cart" %}</button>
</form>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</details>

View File

@@ -26,67 +26,7 @@
{% endautoescape %}
<main aria-label="{% if show_cart %}{% trans "Your cart, general information, add products to your cart" %}{% else %}{% trans "General information, add products to your cart" %}{% endif %}">
{% if show_cart %}
<details class="panel panel-primary cart" open>
<summary class="panel-heading">
<h3 class="panel-title">
<span>
<i class="fa fa-shopping-cart" aria-hidden="true"></i>
<strong>{% trans "Your cart" %}</strong>
</span>
<span>
<strong id="cart-deadline-short" data-expires="{{ cart.first_expiry|date:"Y-m-d H:i:sO" }}" aria-hidden="true">
{% if cart.minutes_left > 0 or cart.seconds_left > 0 %}
{{ cart.minutes_left|stringformat:"02d" }}:{{ cart.seconds_left|stringformat:"02d" }}
{% else %}
{% trans "Cart expired" %}
{% endif %}
</strong>
<i class="fa fa-angle-down collapse-indicator" aria-hidden="true"></i>
</span>
</h3>
</summary>
<div>
<div class="panel-body">
{% include "pretixpresale/event/fragment_cart.html" with cart=cart event=request.event editable=True %}
<em id="cart-deadline" data-expires="{{ cart.first_expiry|date:"Y-m-d H:i:sO" }}">
{% if cart.minutes_left > 0 or cart.seconds_left > 0 %}
{% blocktrans trimmed with minutes=cart.minutes_left %}
The items in your cart are reserved for you for {{ minutes }} minutes.
{% endblocktrans %}
{% else %}
{% trans "The items in your cart are no longer reserved for you." %}
{% endif %}
</em>
<div class="row checkout-button-row">
<div class="col-md-4 col-sm-6 col-xs-12 hidden-xs">
<form method="post" data-asynctask action="{% eventurl request.event "presale:event.cart.clear" cart_namespace=cart_namespace %}">
{% csrf_token %}
<button class="btn btn-block btn-default btn-lg" type="submit">
<i class="fa fa-close" aria-hidden="true"></i> {% trans "Empty cart" %}</button>
</form>
</div>
<div class="col-md-4 col-sm-6 col-md-offset-4 col-xs-12">
<a class="btn btn-block btn-primary btn-lg"
href="{% eventurl request.event "presale:event.checkout.start" cart_namespace=cart_namespace %}">
{% if has_addon_choices or cart.total == 0 %}
<i class="fa fa-shopping-cart" aria-hidden="true"></i> {% trans "Continue" %}
{% else %}
<i class="fa fa-shopping-cart" aria-hidden="true"></i> {% trans "Proceed with checkout" %}
{% endif %}
</a>
</div>
<div class="visible-xs-block col-xs-12">
<form method="post" data-asynctask action="{% eventurl request.event "presale:event.cart.clear" cart_namespace=cart_namespace %}">
{% csrf_token %}
<button class="btn btn-block btn-default btn-lg" type="submit">
<i class="fa fa-close" aria-hidden="true"></i> {% trans "Empty cart" %}</button>
</form>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</details>
{% include "pretixpresale/event/fragment_cart_box.html" with open=1 %}
{% endif %}
{% if request.event.has_subevents %}

View File

@@ -9,6 +9,10 @@
{% block title %}{% trans "Voucher redemption" %}{% endblock %}
{% block content %}
{% if show_cart %}
{% include "pretixpresale/event/fragment_cart_box.html" with open=request.GET.show_cart %}
{% endif %}
<h2>{% trans "Voucher redemption" %}</h2>
{% if subevent %}

View File

@@ -66,7 +66,7 @@ from pretix.base.views.tasks import AsyncAction
from pretix.multidomain.urlreverse import eventreverse
from pretix.presale.views import (
EventViewMixin, allow_cors_if_namespaced, allow_frame_if_namespaced,
iframe_entry_view_wrapper,
iframe_entry_view_wrapper, CartMixin,
)
from pretix.presale.views.event import (
get_grouped_items, item_group_by_category,
@@ -513,7 +513,7 @@ class CartAdd(EventViewMixin, CartActionMixin, AsyncAction, View):
@method_decorator(allow_frame_if_namespaced, 'dispatch')
@method_decorator(iframe_entry_view_wrapper, 'dispatch')
class RedeemView(NoSearchIndexViewMixin, EventViewMixin, TemplateView):
class RedeemView(NoSearchIndexViewMixin, EventViewMixin, CartMixin, TemplateView):
template_name = "pretixpresale/event/voucher.html"
def get_context_data(self, **kwargs):
@@ -541,6 +541,9 @@ class RedeemView(NoSearchIndexViewMixin, EventViewMixin, TemplateView):
for item in items if item.has_variations
)
context['cart'] = self.get_cart()
context['show_cart'] = context['cart']['positions']
# Regroup those by category
context['items_by_category'] = item_group_by_category(items)