Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix reviews remarks
fowczarekaaa9542b5ea5
diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.pyindex 0c550104fe..3da24b4ab6 100644--- a/saleor/graphql/product/types.py+++ b/saleor/graphql/product/types.py@@ -9,7 +9,7 @@ from graphql.error import GraphQLErrorfrom ...product import modelsfrom ...product.templatetags.product_images import (- get_thumbnail, get_product_image_thumbnail)+ get_product_image_thumbnail, get_thumbnail)from ...product.utils import calculate_revenue_for_variantfrom ...product.utils.availability import get_availabilityfrom ...product.utils.costs import (@@ -101,14 +101,12 @@ def resolve_attribute_value_type(attribute_value):def resolve_background_image(background_image, alt, size, info):- if background_image:- if size:- url = get_thumbnail(background_image, size, method='thumbnail')- else:- url = background_image.url- url = info.context.build_absolute_uri(url)- return Image(url, alt)- return None+ if size:+ url = get_thumbnail(background_image, size, method='thumbnail')+ else:+ url = background_image.url+ url = info.context.build_absolute_uri(url)+ return Image(url, alt)class AttributeValue(CountableDjangoObjectType):@@ -273,12 +271,10 @@ class Product(CountableDjangoObjectType):deprecation_reason=dedent("""thumbnailUrl is deprecated, usethumbnail instead"""))thumbnail = graphene.Field(- lambda: ProductImage,- description='The main thumbnail for a product.',+ Image, description='The main thumbnail for a product.',size=graphene.Argument(graphene.Int, description='Size of thumbnail'))availability = graphene.Field(- ProductAvailability,- description=dedent("""Informs about product's availability in the+ ProductAvailability, description=dedent("""Informs about product's availability in thestorefront, current price and discounts."""))price = graphene.Field(Money,@@ -325,17 +321,13 @@ class Product(CountableDjangoObjectType):return info.context.build_absolute_uri(url)def resolve_thumbnail(self, info, *, size=None):+ image = self.get_first_image()if not size:size = 255- product_image = self.get_first_image()- if product_image:- url = get_product_image_thumbnail(- product_image, size, method='thumbnail')- thumbnail_image = models.ProductImage(- alt=product_image.alt, product=product_image.product,- sort_order=product_image.sort_order)- thumbnail_image.image = Image(url)- return thumbnail_image+ url = get_product_image_thumbnail(image, size, method='thumbnail')+ url = info.context.build_absolute_uri(url)+ alt = image.alt if image else None+ return Image(alt=alt, url=url)def resolve_url(self, info):return self.get_absolute_url()@@ -449,6 +441,8 @@ class Collection(CountableDjangoObjectType):model = models.Collectiondef resolve_background_image(self, info, size=None, **kwargs):+ if not self.background_image:+ return Nonereturn resolve_background_image(self.background_image, self.background_image_alt, size, info)@@ -490,6 +484,8 @@ class Category(CountableDjangoObjectType):return gql_optimizer.query(qs, info)def resolve_background_image(self, info, size=None, **kwargs):+ if not self.background_image:+ return Nonereturn resolve_background_image(self.background_image, self.background_image_alt, size, info)diff --git a/saleor/product/models.py b/saleor/product/models.pyindex df0295c13a..8ad835061e 100644--- a/saleor/product/models.py+++ b/saleor/product/models.py@@ -295,9 +295,7 @@ class ProductVariant(models.Model):def get_first_image(self):images = list(self.images.all())- if images:- return images[0]- return self.product.get_first_image()+ return images[0] if images else self.product.get_first_image()def get_ajax_label(self, discounts=None):price = self.get_price(discounts).grossdiff --git a/saleor/product/templatetags/product_images.py b/saleor/product/templatetags/product_images.pyindex 2246edf4b5..2e49dc2825 100644--- a/saleor/product/templatetags/product_images.py+++ b/saleor/product/templatetags/product_images.py@@ -99,6 +99,5 @@ def get_thumbnail(image_file, size, method, rendition_key_set='products'):@register.simple_tag()def get_product_image_thumbnail(instance, size, method):- if instance:- return get_thumbnail(instance.image, size, method)- return get_thumbnail(None, size, method)+ image_file = instance.image if instance else None+ return get_thumbnail(image_file, size, method)