forked from CGM_Public/pretix_original
Add clever handling of plus button in cart with voucher (#2893)
This commit is contained in:
@@ -267,6 +267,10 @@
|
||||
data-asynctask-text="{% blocktrans with time=event.settings.reservation_time %}Once the items are in your cart, you will have {{ time }} minutes to complete your purchase.{% endblocktrans %}"
|
||||
method="post" data-asynctask>
|
||||
<input type="hidden" name="subevent" value="{{ line.subevent_id|default_if_none:"" }}" />
|
||||
{% if line.voucher and not line.voucher.seat %}
|
||||
<input type="hidden" name="_voucher_code" value="{{ line.voucher.code }}" />
|
||||
<input type="hidden" name="_voucher_ignore_if_redeemed" value="on" />
|
||||
{% endif %}
|
||||
{% csrf_token %}
|
||||
{% if line.variation %}
|
||||
<input type="hidden" name="variation_{{ line.item.id }}_{{ line.variation.id }}"
|
||||
|
||||
@@ -136,7 +136,7 @@ class CartActionMixin:
|
||||
except InvoiceAddress.DoesNotExist:
|
||||
return InvoiceAddress()
|
||||
|
||||
def _item_from_post_value(self, key, value, voucher=None):
|
||||
def _item_from_post_value(self, key, value, voucher=None, voucher_ignore_if_redeemed=False):
|
||||
if value.strip() == '' or '_' not in key:
|
||||
return
|
||||
|
||||
@@ -161,6 +161,7 @@ class CartActionMixin:
|
||||
'seat': value,
|
||||
'price': price,
|
||||
'voucher': voucher,
|
||||
'voucher_ignore_if_redeemed': voucher_ignore_if_redeemed,
|
||||
'subevent': subevent
|
||||
}
|
||||
except ValueError:
|
||||
@@ -183,6 +184,7 @@ class CartActionMixin:
|
||||
'count': amount,
|
||||
'price': price,
|
||||
'voucher': voucher,
|
||||
'voucher_ignore_if_redeemed': voucher_ignore_if_redeemed,
|
||||
'subevent': subevent
|
||||
}
|
||||
except ValueError:
|
||||
@@ -195,6 +197,7 @@ class CartActionMixin:
|
||||
'count': amount,
|
||||
'price': price,
|
||||
'voucher': voucher,
|
||||
'voucher_ignore_if_redeemed': voucher_ignore_if_redeemed,
|
||||
'subevent': subevent
|
||||
}
|
||||
except ValueError:
|
||||
@@ -219,7 +222,8 @@ class CartActionMixin:
|
||||
for key, values in req_items:
|
||||
for value in values:
|
||||
try:
|
||||
item = self._item_from_post_value(key, value, self.request.POST.get('_voucher_code'))
|
||||
item = self._item_from_post_value(key, value, self.request.POST.get('_voucher_code'),
|
||||
voucher_ignore_if_redeemed=self.request.POST.get('_voucher_ignore_if_redeemed') == 'on')
|
||||
except CartError as e:
|
||||
messages.error(self.request, str(e))
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user