forked from CGM_Public/pretix_original
* 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 %}
|
{% endfor %}
|
||||||
</section>
|
</section>
|
||||||
{% endfor %}
|
{% 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="row-fluid checkout-button-row">
|
||||||
<div class="col-md-4 col-md-offset-8 col-xs-12">
|
<div class="col-md-4 col-md-offset-8 col-xs-12">
|
||||||
<button class="btn btn-block btn-primary btn-lg" type="submit">
|
<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(
|
).annotate(quotac=Count('quotas')).filter(
|
||||||
quotac__gt=0
|
quotac__gt=0
|
||||||
).order_by('category__position', 'category_id', 'position', 'name')
|
).order_by('category__position', 'category_id', 'position', 'name')
|
||||||
|
display_add_to_cart = False
|
||||||
for item in items:
|
for item in items:
|
||||||
item.available_variations = list(item.variations.filter(active=True, quotas__isnull=False).distinct())
|
item.available_variations = list(item.variations.filter(active=True, quotas__isnull=False).distinct())
|
||||||
item.has_variations = item.variations.exists()
|
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,
|
if item.cached_availability[1] is not None else sys.maxsize,
|
||||||
int(self.request.event.settings.max_items_per_order))
|
int(self.request.event.settings.max_items_per_order))
|
||||||
item.price = item.default_price
|
item.price = item.default_price
|
||||||
|
display_add_to_cart = display_add_to_cart or item.order_max > 0
|
||||||
else:
|
else:
|
||||||
for var in item.available_variations:
|
for var in item.available_variations:
|
||||||
var.cached_availability = list(var.check_quotas())
|
var.cached_availability = list(var.check_quotas())
|
||||||
var.order_max = min(var.cached_availability[1]
|
var.order_max = min(var.cached_availability[1]
|
||||||
if var.cached_availability[1] is not None else sys.maxsize,
|
if var.cached_availability[1] is not None else sys.maxsize,
|
||||||
int(self.request.event.settings.max_items_per_order))
|
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
|
var.price = var.default_price if var.default_price is not None else item.default_price
|
||||||
if len(item.available_variations) > 0:
|
if len(item.available_variations) > 0:
|
||||||
item.min_price = min([v.price for v in item.available_variations])
|
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
|
# Regroup those by category
|
||||||
context['items_by_category'] = item_group_by_category(items)
|
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')
|
vouchers_exist = self.request.event.get_cache().get('vouchers_exist')
|
||||||
if vouchers_exist is None:
|
if vouchers_exist is None:
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ class ItemDisplayTest(EventTestMixin, SoupTest):
|
|||||||
q.items.add(item)
|
q.items.add(item)
|
||||||
html = self.client.get('/%s/%s/' % (self.orga.slug, self.event.slug))
|
html = self.client.get('/%s/%s/' % (self.orga.slug, self.event.slug))
|
||||||
self.assertNotIn("Early-bird", html)
|
self.assertNotIn("Early-bird", html)
|
||||||
|
self.assertNotIn('checkout-button-row', html)
|
||||||
|
|
||||||
def test_without_category(self):
|
def test_without_category(self):
|
||||||
q = Quota.objects.create(event=self.event, name='Quota', size=2)
|
q = Quota.objects.create(event=self.event, name='Quota', size=2)
|
||||||
@@ -62,6 +63,7 @@ class ItemDisplayTest(EventTestMixin, SoupTest):
|
|||||||
q.items.add(item)
|
q.items.add(item)
|
||||||
doc = self.get_doc('/%s/%s/' % (self.orga.slug, self.event.slug))
|
doc = self.get_doc('/%s/%s/' % (self.orga.slug, self.event.slug))
|
||||||
self.assertIn("Early-bird", doc.select("section .product-row")[0].text)
|
self.assertIn("Early-bird", doc.select("section .product-row")[0].text)
|
||||||
|
self.assertIn("Add to cart", doc.select("div button")[0].text)
|
||||||
|
|
||||||
def test_timely_available(self):
|
def test_timely_available(self):
|
||||||
q = Quota.objects.create(event=self.event, name='Quota', size=2)
|
q = Quota.objects.create(event=self.event, name='Quota', size=2)
|
||||||
@@ -217,7 +219,7 @@ class DeadlineTest(EventTestMixin, TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertNotIn('alert-info', response.rendered_content)
|
self.assertNotIn('alert-info', response.rendered_content)
|
||||||
self.assertIn('checkout-button-row', response.rendered_content)
|
self.assertNotIn('checkout-button-row', response.rendered_content)
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
'/%s/%s/cart/add' % (self.orga.slug, self.event.slug),
|
'/%s/%s/cart/add' % (self.orga.slug, self.event.slug),
|
||||||
{
|
{
|
||||||
@@ -235,7 +237,7 @@ class DeadlineTest(EventTestMixin, TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertNotIn('alert-info', response.rendered_content)
|
self.assertNotIn('alert-info', response.rendered_content)
|
||||||
self.assertIn('checkout-button-row', response.rendered_content)
|
self.assertNotIn('checkout-button-row', response.rendered_content)
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
'/%s/%s/cart/add' % (self.orga.slug, self.event.slug),
|
'/%s/%s/cart/add' % (self.orga.slug, self.event.slug),
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user