Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Rename and make more general resolve_instance_attributes function
Adam Janik0311b395a363
diff --git a/saleor/dashboard/graphql/product/mutations.py b/saleor/dashboard/graphql/product/mutations.pyindex 5c9031f428..ccb1e1157c 100644--- a/saleor/dashboard/graphql/product/mutations.py+++ b/saleor/dashboard/graphql/product/mutations.py@@ -47,7 +47,7 @@ class CategoryDelete(StaffMemberRequiredMutation, ModelDeleteMutation):model = models.Category-class ValuesInput(InputObjectType):+class AttributeValueInput(InputObjectType):slug = graphene.String(required=True)value = graphene.String(required=True)@@ -56,7 +56,7 @@ class ProductCreateMutation(StaffMemberRequiredMutation, ModelFormMutation):class Arguments:product_type_id = graphene.ID()category_id = graphene.ID()- attributes = graphene.Argument(graphene.List(ValuesInput))+ attributes = graphene.Argument(graphene.List(AttributeValueInput))class Meta:form_class = ProductForm@@ -85,7 +85,7 @@ class ProductDeleteMutation(StaffMemberRequiredMutation, ModelDeleteMutation):class ProductUpdateMutation(StaffMemberRequiredMutation,ModelFormUpdateMutation):class Arguments:- attributes = graphene.Argument(graphene.List(ValuesInput))+ attributes = graphene.Argument(graphene.List(AttributeValueInput))category_id = graphene.ID()class Meta:diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.pyindex 948bb8d650..fc36c649c9 100644--- a/saleor/graphql/product/types.py+++ b/saleor/graphql/product/types.py@@ -31,7 +31,7 @@ class ProductVariant(CountableDjangoObjectType):return self.get_stock_quantity()def resolve_attributes(self, info):- return resolve_instance_attributes(instance=self, info=info)+ return resolve_attribute_list(self.attributes)class ProductAvailability(graphene.ObjectType):@@ -73,7 +73,7 @@ class Product(CountableDjangoObjectType):return ProductAvailability(**availability._asdict())def resolve_attributes(self, info):- return resolve_instance_attributes(instance=self, info=info)+ return resolve_attribute_list(self.attributes)class ProductType(CountableDjangoObjectType):@@ -151,14 +151,18 @@ class ProductAttribute(CountableDjangoObjectType):return self.values.all()-def resolve_instance_attributes(instance, info):- product_attributes = dict(- models.ProductAttribute.objects.values_list('id', 'slug'))- attribute_values = dict(- models.AttributeChoiceValue.objects.values_list('id', 'slug'))+def resolve_attribute_list(attributes=None):+ """+ :param attributes: dict+ :return: list of objects of type SelectedAttribute+ """attribute_list = []- if instance.attributes.items():- for k, v in instance.attributes.items():+ if attributes:+ product_attributes = dict(+ models.ProductAttribute.objects.values_list('id', 'slug'))+ attribute_values = dict(+ models.AttributeChoiceValue.objects.values_list('id', 'slug'))+ for k, v in attributes.items():value = Nonename = product_attributes.get(int(k))if v:diff --git a/tests/dashboard/test_graphql.py b/tests/dashboard/test_graphql.pyindex f5d5ec08c0..5e5b89ccf4 100644--- a/tests/dashboard/test_graphql.py+++ b/tests/dashboard/test_graphql.py@@ -272,7 +272,7 @@ def test_create_product($isPublished: Boolean!,$isFeatured: Boolean!,$price: Float!,- $attributes: [ValuesInput]) {+ $attributes: [AttributeValueInput]) {productCreate(categoryId: $categoryId,productTypeId: $productTypeId,@@ -370,7 +370,7 @@ def test_update_product($isPublished: Boolean!,$isFeatured: Boolean!,$price: Float!,- $attributes: [ValuesInput]) {+ $attributes: [AttributeValueInput]) {productUpdate(categoryId: $categoryId,id: $productId,