Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add sku varidation
fowczarek2f3f3b01ce0f
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.pyindex c3624e351a..a6b3f66126 100644--- a/saleor/graphql/product/mutations/products.py+++ b/saleor/graphql/product/mutations/products.py@@ -324,8 +324,19 @@ class ProductCreate(ModelMutation):else:cleaned_input['attributes'] = attributesclean_seo_fields(cleaned_input)+ cls.clean_sku(product_type, cleaned_input, errors)return cleaned_input+ @classmethod+ def clean_sku(cls, product_type, cleaned_input, errors):+ """Check if mutation have sku when ProductType without Variants.++ We must ensure that the Product without Variant has the necessary+ fields to create the default variant only in create mutation.+ """+ if not product_type.has_variants and not cleaned_input.get('sku'):+ cls.add_error(errors, 'sku', 'This field cannot be blank.')+@classmethod@transaction.atomicdef save(cls, info, instance, cleaned_input):@@ -363,6 +374,10 @@ class ProductUpdate(ProductCreate):description = 'Updates an existing product.'model = models.Product+ @classmethod+ def clean_sku(cls, product_type, cleaned_input, errors):+ pass+@classmethod@transaction.atomicdef save(cls, info, instance, cleaned_input):