Add clever handling of plus button in cart with voucher (#2893)

This commit is contained in:
Raphael Michel
2022-11-14 16:55:39 +01:00
committed by GitHub
parent 5b8228bea0
commit e32e7e2a50
4 changed files with 63 additions and 4 deletions

View File

@@ -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 }}"

View File

@@ -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