Skip to content

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

Limit size choices in ShirtForm only to available sizes

Artur Smęt2430818eec0a
diff --git a/saleor/product/forms.py b/saleor/product/forms.py
index 6267ae4bbc..3e0c5010ec 100644
--- a/saleor/product/forms.py
+++ b/saleor/product/forms.py
@@ -15,6 +15,13 @@ class ShirtForm(AddToCartForm):
size = forms.ChoiceField(choices=ShirtVariant.SIZE_CHOICES,
widget=forms.RadioSelect())
+ def __init__(self, *args, **kwargs):
+ super(ShirtForm, self).__init__(*args, **kwargs)
+ available_sizes = [
+ (p.size, p.get_size_display) for p in self.product.variants.all()
+ ]
+ self.fields['size'].choices = available_sizes
+
def get_variant(self, clean_data):
size = clean_data.get('size')
return ShirtVariant.objects.get(size=size,