Skip to content

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

Generate category slug if not provided

Marcin Gębala76011bd4a1c4
diff --git a/saleor/graphql/product/mutations.py b/saleor/graphql/product/mutations.py
index 8fa297a6c9..71b39f1f8c 100644
--- a/saleor/graphql/product/mutations.py
+++ b/saleor/graphql/product/mutations.py
@@ -1,4 +1,5 @@
import graphene
+from django.template.defaultfilters import slugify
from graphene.types import InputObjectType
from graphene_file_upload import Upload
from graphql_jwt.decorators import permission_required
@@ -29,6 +30,13 @@ class CategoryCreateMutation(ModelMutation):
description = 'Creates a new category.'
model = models.Category
+ @classmethod
+ def clean_input(cls, info, instance, input, errors):
+ cleaned_input = super().clean_input(info, instance, input, errors)
+ if 'slug' not in cleaned_input:
+ cleaned_input['slug'] = slugify(cleaned_input['name'])
+ return cleaned_input
+
@classmethod
def user_is_allowed(cls, user, input):
return user.has_perm('category.edit_category')
@@ -173,6 +181,7 @@ class AttributeValueInput(InputObjectType):
value = graphene.String(
required=True, description='Value of an attribute.')
+
class ProductInput(graphene.InputObjectType):
attributes = graphene.List(AttributeValueInput)
available_on = graphene.String()