Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Change product varinat images to a list in API
fowczarek01292797f16c
diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.pyindex 14c3356710..66ffce0be8 100644--- a/saleor/graphql/order/types.py+++ b/saleor/graphql/order/types.py@@ -91,7 +91,7 @@ class Fulfillment(CountableDjangoObjectType):lines = gql_optimizer.field(graphene.List(FulfillmentLine,- description='List of fulfillment lines for the fulfillment'),+ description='List of lines for the fulfillment'),model_field='lines')status_display = graphene.String(description='User-friendly fulfillment status.')diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.pyindex 4edb286c99..55a5c5efc7 100644--- a/saleor/graphql/product/types.py+++ b/saleor/graphql/product/types.py@@ -129,6 +129,28 @@ class SelectedAttribute(graphene.ObjectType):description = 'Represents a custom attribute.'+class ProductImage(CountableDjangoObjectType):+ url = graphene.String(+ required=True,+ description='The URL of the image.',+ size=graphene.Int(description='Size of the image'))++ class Meta:+ description = 'Represents a product image.'+ exclude_fields = [+ 'image', 'product', 'ppoi', 'productvariant_set',+ 'variant_images']+ interfaces = [relay.Node]+ model = models.ProductImage++ def resolve_url(self, info, *, size=None):+ if size:+ url = get_thumbnail(self.image, size, method='thumbnail')+ else:+ url = self.image.url+ return info.context.build_absolute_uri(url)++class ProductVariant(CountableDjangoObjectType):stock_quantity = graphene.Int(required=True, description='Quantity of a product available for sale.')@@ -151,6 +173,11 @@ class ProductVariant(CountableDjangoObjectType):period of time. Note: this field should be queried using`reportProductSales` query as it uses optimizations suitablefor such calculations.'''))+ images = gql_optimizer.field(+ graphene.List(+ ProductImage,+ description='List of images for the product variant'),+ model_field='images')class Meta:description = dedent("""Represents a version of a product such as@@ -189,6 +216,9 @@ class ProductVariant(CountableDjangoObjectType):start_date = reporting_period_to_date(period)return calculate_revenue_for_variant(self, start_date)+ def resolve_images(self, info):+ return self.images.all()+class ProductAvailability(graphene.ObjectType):available = graphene.Boolean()@@ -429,25 +459,3 @@ class Category(CountableDjangoObjectType):qs = models.Product.objects.available_products()qs = qs.filter(category__in=tree)return gql_optimizer.query(qs, info)---class ProductImage(CountableDjangoObjectType):- url = graphene.String(- required=True,- description='The URL of the image.',- size=graphene.Int(description='Size of the image'))-- class Meta:- description = 'Represents a product image.'- exclude_fields = [- 'image', 'product', 'ppoi', 'productvariant_set',- 'variant_images']- interfaces = [relay.Node]- model = models.ProductImage-- def resolve_url(self, info, *, size=None):- if size:- url = get_thumbnail(self.image, size, method='thumbnail')- else:- url = self.image.url- return info.context.build_absolute_uri(url)diff --git a/tests/api/test_variant.py b/tests/api/test_variant.pyindex 44bd10a8ff..bc21fd7946 100644--- a/tests/api/test_variant.py+++ b/tests/api/test_variant.py@@ -31,11 +31,7 @@ def test_fetch_variant(staff_api_client, product, permission_manage_products):amount}images {- edges {- node {- id- }- }+ id}namepriceOverride {