Skip to content

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

Add variant attrs validators to product class

Krzysztof Wolskic33e49f669a6
diff --git a/saleor/dashboard/product/forms.py b/saleor/dashboard/product/forms.py
index 06805dad28..e4ac2cc6df 100644
--- a/saleor/dashboard/product/forms.py
+++ b/saleor/dashboard/product/forms.py
@@ -43,8 +43,14 @@ class ProductClassForm(forms.ModelForm):
def clean(self):
data = super(ProductClassForm, self).clean()
+ has_variants = self.cleaned_data.get('product_attributes')
product_attr = set(self.cleaned_data.get('product_attributes', []))
variant_attr = set(self.cleaned_data.get('variant_attributes', []))
+ if not has_variants and len(variant_attr) > 0:
+ msg = pgettext_lazy(
+ "Product Class Errors",
+ "This class has no variants options selected.")
+ self.add_error('variant_attributes', msg)
if len(product_attr & variant_attr) > 0:
msg = pgettext_lazy(
"Product Class Errors",