Repository: pretix/pretix

Issue:
Max Ticket Amount per Order not working
Max amount is set to 0 in my setup, but the shop does not allow more than one. Changing the value to something > 0 works (e.g. 2,3, etc.), but 0 only allows 1 Ticket.

The max amount field also accepts values like -1, which might actually break things in a worse way, just a side note though.

pretix version 4.6.0

![image](https://user-images.githubusercontent.com/5830192/153158048-0a6e9b68-e2d7-4500-8855-0922478cf895.png)
![image](https://user-images.githubusercontent.com/5830192/153158515-39be2126-cffc-484a-944c-b98d4b97ff7d.png)




Discussion:
Could you maybe just keep the field empty? Not sure what the correct behaviour for 0 should be. We should probably limit the field to values of 1 or higher
Hi Raphael,

leaving it empty shows the same behavior (1 ticket max). This worked before by the way, looks like regression in 4.6

Your original description text for that field:
> Dieses Produkt kann pro Bestellung höchstens so oft bestellt werden wie hier angegeben. Wenn das Feld leer ist oder auf 0 gesetzt wird, gibt es keine Beschränkung. Die Beschränkung für die Gesamtanzahl von Produkten in einer Bestellung bleibt davon unberührt.

Best,
Alex
Could you check your settings regarding max. number of products in cart (Einstellungen => Allgemein => Tab „Warenkorb“)? I can only get it to work the way you describe it when I set the maximum number of products in the cart to 1. Then leaving max. ticket amount per order on the product empty or 0, it defaults to max number of products in cart.

Two things:

1. obviously this is a config error, but should we check in presale if max. num in cart is smaller than max. num in products?
2. max. as well as min number of products on products settings should be an `<input type="number">` as it is on the cart settings.

I will fix the number input (2). Regarding (1) let me know, what you think, we should do. 
> obviously this is a config error, but should we check in presale if max. num in cart is smaller than max. num in products?

I don't think so. Since these two configs are in different places, it would be annoying if you would need to change them in a specific order to get around the vlaidation.

> max. as well as min number of products on products settings should be an <input type="number"> as it is on the cart settings.

fine with me
> > obviously this is a config error, but should we check in presale if max. num in cart is smaller than max. num in products?
> 
> I don't think so. Since these two configs are in different places, it would be annoying if you would need to change them in a specific order to get around the vlaidation.

Sorry, I wasn’t clear. I meant, should we check in pretix-presale (not in pretix-control when editing config) to limit number-inputs to `min(ev.max_items_per_order, item.max_per_order)`? This does not prevent a misconfig, but it helps users not entering to add 5 products and then get an error-message that only 3 products total are allowed in basket. It is a tiny edge-case, I know, and probably not worth it as it is already handled server-side.
> Could you check your settings regarding max. number of products in cart (Einstellungen => Allgemein => Tab „Warenkorb“)? 

Okay, my bad, I forgot there's a second setting for this. This is indeed set to 1.

Resolving patch:
diff --git a/src/pretix/base/models/items.py b/src/pretix/base/models/items.py
--- a/src/pretix/base/models/items.py
+++ b/src/pretix/base/models/items.py
@@ -44,7 +44,7 @@
 import pytz
 from django.conf import settings
 from django.core.exceptions import ValidationError
-from django.core.validators import RegexValidator
+from django.core.validators import MinValueValidator, RegexValidator
 from django.db import models
 from django.db.models import Q
 from django.utils import formats
@@ -479,12 +479,14 @@ class Item(LoggedModel):
     min_per_order = models.IntegerField(
         verbose_name=_('Minimum amount per order'),
         null=True, blank=True,
+        validators=[MinValueValidator(0)],
         help_text=_('This product can only be bought if it is added to the cart at least this many times. If you keep '
                     'the field empty or set it to 0, there is no special limit for this product.')
     )
     max_per_order = models.IntegerField(
         verbose_name=_('Maximum amount per order'),
         null=True, blank=True,
+        validators=[MinValueValidator(0)],
         help_text=_('This product can only be bought at most this many times within one order. If you keep the field '
                     'empty or set it to 0, there is no special limit for this product. The limit for the maximum '
                     'number of items in the whole order applies regardless.')
diff --git a/src/pretix/control/forms/item.py b/src/pretix/control/forms/item.py
--- a/src/pretix/control/forms/item.py
+++ b/src/pretix/control/forms/item.py
@@ -627,7 +627,9 @@ class Meta:
                 'class': 'scrolling-multiple-choice'
             }),
             'generate_tickets': TicketNullBooleanSelect(),
-            'show_quota_left': ShowQuotaNullBooleanSelect()
+            'show_quota_left': ShowQuotaNullBooleanSelect(),
+            'max_per_order': forms.widgets.NumberInput(attrs={'min': 0}),
+            'min_per_order': forms.widgets.NumberInput(attrs={'min': 0}),
         }
 
 


Test patch: