Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
ADd ThubmnailUrl to OrderLines
Pacu205d5350bed81
diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.pyindex 555ef0dce9..5f21c7a8f2 100644--- a/saleor/graphql/order/types.py+++ b/saleor/graphql/order/types.py@@ -1,11 +1,13 @@+from decimal import Decimal+import graphenefrom graphene import relayfrom ...order import OrderEvents, models+from ...product.templatetags.product_images import get_thumbnailfrom ..account.types import Userfrom ..core.types.common import CountableDjangoObjectTypefrom ..core.types.money import Money, TaxedMoney-from decimal import DecimalOrderEventsEnum = graphene.Enum.from_enum(OrderEvents)@@ -163,9 +165,21 @@ class Order(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'))+class Meta:description = 'Represents order line of particular order.'model = models.OrderLineinterfaces = [relay.Node]exclude_fields = ['order', 'unit_price_gross', 'unit_price_net', 'variant']++ def resolve_thumbnail_url(self, info, size=None):+ if not self.variant_id:+ return None+ if not size:+ size = 255+ return get_thumbnail(+ self.variant.get_first_image(), size, method='thumbnail')diff --git a/tests/api/test_order.py b/tests/api/test_order.pyindex 5e444e32e5..5697e01f5a 100644--- a/tests/api/test_order.py+++ b/tests/api/test_order.py@@ -15,6 +15,40 @@ from saleor.order.models import Order, OrderStatus, Payment, PaymentStatusfrom tests.utils import get_graphql_content+def test_orderline_query(admin_api_client, fulfilled_order):+ order = fulfilled_order+ query = """+ query OrdersQuery {+ orders(first: 1) {+ edges {+ node {+ lines {+ edges {+ node {+ thumbnailUrl(size: 540)+ }+ }+ }+ }+ }+ }+ }+ """+ line = order.lines.first()+ line.variant = None+ line.save()++ response = admin_api_client.post(+ reverse('api'), {'query': query})+ content = get_graphql_content(response)+ assert 'errors' not in content+ order_data = content['data']['orders']['edges'][0]['node']+ lines_data = order_data['lines']['edges']+ thumbnails = [l['node']['thumbnailUrl'] for l in lines_data]+ assert sorted(thumbnails) == [+ None, '/static/images/placeholder540x540.png']++def test_order_query(admin_api_client, fulfilled_order):order = fulfilled_orderquery = """