Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Use maximum orderable quantity defined in settings

Artur Smęt68f740ea3e94
diff --git a/saleor/cart/forms.py b/saleor/cart/forms.py
index 8611ef40e3..bfb22c8631 100644
--- a/saleor/cart/forms.py
+++ b/saleor/cart/forms.py
@@ -2,6 +2,7 @@ from __future__ import unicode_literals
from django import forms
from django.core.exceptions import ObjectDoesNotExist, NON_FIELD_ERRORS
+from django.conf import settings
from django.utils.translation import pgettext_lazy, ugettext_lazy
from satchless.item import InsufficientStock
@@ -9,8 +10,9 @@ from satchless.item import InsufficientStock
class QuantityField(forms.IntegerField):
def __init__(self, **kwargs):
- super(QuantityField, self).__init__(min_value=0, max_value=999,
- initial=1, **kwargs)
+ super(QuantityField, self).__init__(
+ min_value=0, max_value=settings.MAX_CART_LINE_QUANTITY,
+ initial=1, **kwargs)
class AddToCartForm(forms.Form):
@@ -87,7 +89,7 @@ class ReplaceCartLineForm(AddToCartForm):
super(ReplaceCartLineForm, self).__init__(*args, **kwargs)
self.cart_line = self.cart.get_line(self.variant)
self.fields['quantity'].widget.attrs = {
- 'min': 1, 'max': self.variant.get_stock_quantity()}
+ 'min': 1, 'max': settings.MAX_CART_LINE_QUANTITY}
def clean_quantity(self):
quantity = self.cleaned_data['quantity']
diff --git a/saleor/settings.py b/saleor/settings.py
index 9f7c4a2334..ae6ebfb52d 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -258,6 +258,7 @@ MESSAGE_TAGS = {
messages.ERROR: 'danger'}
LOW_STOCK_THRESHOLD = 10
+MAX_CART_LINE_QUANTITY = os.environ.get('MAX_CART_LINE_QUANTITY', 50)
PAGINATE_BY = 16