Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add thumbnail to OrderLine, deprecate thumbnailUrl
Michał Jelonek476b8f39452c
diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.pyindex 38856bfea7..1f3bab2ea5 100644--- a/saleor/graphql/order/types.py+++ b/saleor/graphql/order/types.py@@ -8,6 +8,7 @@ from ..account.types import Userfrom ..core.connection import CountableDjangoObjectTypefrom ..core.types.money import Money, TaxedMoneyfrom ..payment.types import OrderAction, Payment, PaymentChargeStatusEnum+from ..product.types import Imagefrom ..shipping.types import ShippingMethodfrom .enums import OrderEventsEmailsEnum, OrderEventsEnumfrom .utils import applicable_shipping_methods, can_finalize_draft_order@@ -106,7 +107,12 @@ class Fulfillment(CountableDjangoObjectType):class OrderLine(CountableDjangoObjectType):thumbnail_url = graphene.String(description='The URL of a main thumbnail for the ordered product.',- size=graphene.Int(description='Size of the image'))+ size=graphene.Int(description='Size of the image'),+ deprecation_reason=(+ 'thumbnailUrl is deprecated, use thumbnail instead'))+ thumbnail = graphene.Field(+ Image, description='The main thumbnail for the ordered product.',+ size=graphene.Argument(graphene.Int, description='Size of thumbnail'))unit_price = graphene.Field(TaxedMoney, description='Price of the single item in the order line.')@@ -128,6 +134,18 @@ class OrderLine(CountableDjangoObjectType):self.variant.get_first_image(), size, method='thumbnail')return info.context.build_absolute_uri(url)+ @gql_optimizer.resolver_hints(+ prefetch_related=['variant__images', 'variant__product__images'])+ def resolve_thumbnail(self, info, *, size=None):+ if not self.variant_id:+ return None+ if not size:+ size = 255+ image = self.variant.get_first_image()+ url = get_product_image_thumbnail(image, size, method='thumbnail')+ alt = image.alt if image else None+ return Image(alt=alt, url=info.context.build_absolute_uri(url))+@staticmethoddef resolve_unit_price(self, info):return self.unit_pricediff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 812f7ea393..f8916c7a0c 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -1109,7 +1109,8 @@ type OrderLine implements Node {quantityFulfilled: Int!unitPrice: TaxedMoneytaxRate: Float!- thumbnailUrl(size: Int): String+ thumbnailUrl(size: Int): String @deprecated(reason: "thumbnailUrl is deprecated, use thumbnail instead")+ thumbnail(size: Int): Image}input OrderLineCreateInput {@@ -1170,11 +1171,11 @@ type OrderVoid {}type Page implements Node {- id: ID!publicationDate: DateisPublished: Boolean!seoTitle: StringseoDescription: String+ id: ID!slug: String!title: String!content: String!@@ -1315,11 +1316,11 @@ enum PermissionEnum {}type Product implements Node {+ id: ID!publicationDate: DateisPublished: Boolean!seoTitle: StringseoDescription: String- id: ID!productType: ProductType!name: String!description: String!diff --git a/tests/api/test_order.py b/tests/api/test_order.pyindex 9667367b9b..aabe029af4 100644--- a/tests/api/test_order.py+++ b/tests/api/test_order.py@@ -16,9 +16,8 @@ from saleor.order.models import Order, OrderEventfrom saleor.payment import ChargeStatus, CustomPaymentChoicesfrom saleor.payment.models import Paymentfrom saleor.shipping.models import ShippingMethod-from tests.api.utils import get_graphql_content-from .utils import assert_no_permission+from .utils import assert_no_permission, get_graphql_contentdef test_orderline_query(@@ -31,6 +30,9 @@ def test_orderline_query(node {lines {thumbnailUrl(size: 540)+ thumbnail(size: 540) {+ url+ }}}}@@ -44,11 +46,17 @@ def test_orderline_query(response = staff_api_client.post_graphql(query)content = get_graphql_content(response)order_data = content['data']['orders']['edges'][0]['node']+thumbnails = [l['thumbnailUrl'] for l in order_data['lines']]assert len(thumbnails) == 2assert thumbnails[0] is Noneassert '/static/images/placeholder540x540.png' in thumbnails[1]+ thumbnails = [l['thumbnail'] for l in order_data['lines']]+ assert len(thumbnails) == 2+ assert thumbnails[0] is None+ assert '/static/images/placeholder540x540.png' in thumbnails[1]['url']+def test_order_query(staff_api_client, permission_manage_orders, fulfilled_order,