Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Change Order.lines to list in api

oldPadavan0c2cf0229465
diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.py
index 260f03766f..8ff1893126 100644
--- a/saleor/graphql/order/types.py
+++ b/saleor/graphql/order/types.py
@@ -87,6 +87,27 @@ class FulfillmentLine(CountableDjangoObjectType):
exclude_fields = ['fulfillment']
+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.OrderLine
+ interfaces = [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')
+
+
class Order(CountableDjangoObjectType):
fulfillments = graphene.List(
Fulfillment,
@@ -114,6 +135,9 @@ class Order(CountableDjangoObjectType):
available_shipping_methods = graphene.List(
ShippingMethod, required=False,
description='Shipping methods that can be used with this order.')
+ lines = graphene.List(
+ OrderLine, required=True,
+ description='List of order lines for the order')
class Meta:
description = 'Represents an order in the shop.'
@@ -180,23 +204,6 @@ class Order(CountableDjangoObjectType):
from .resolvers import resolve_shipping_methods
return resolve_shipping_methods(obj, info)
-
-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.OrderLine
- interfaces = [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')
+ @staticmethod
+ def resolve_lines(obj, info):
+ return obj.lines.all()
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 5789bc5322..e519006a25 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -760,7 +760,7 @@ type Order implements Node {
displayGrossPrices: Boolean!
customerNote: String!
weight: Weight
- lines(before: String, after: String, first: Int, last: Int): OrderLineCountableConnection
+ lines: [OrderLine]!
fulfillments: [Fulfillment]!
events: [OrderEvent]
isPaid: Boolean
diff --git a/tests/api/test_order.py b/tests/api/test_order.py
index 6956bebd3c..b26316e97b 100644
--- a/tests/api/test_order.py
+++ b/tests/api/test_order.py
@@ -30,11 +30,7 @@ def test_orderline_query(admin_api_client, fulfilled_order):
edges {
node {
lines {
- edges {
- node {
- thumbnailUrl(size: 540)
- }
- }
+ thumbnailUrl(size: 540)
}
}
}
@@ -50,8 +46,7 @@ def test_orderline_query(admin_api_client, fulfilled_order):
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]
+ thumbnails = [l['thumbnailUrl'] for l in order_data['lines']]
assert len(thumbnails) == 2
assert None in thumbnails
assert '/static/images/placeholder540x540.png' in thumbnails
@@ -77,7 +72,7 @@ def test_order_query(admin_api_client, fulfilled_order, shipping_zone):
}
}
lines {
- totalCount
+ id
}
fulfillments {
fulfillmentOrder
@@ -123,7 +118,7 @@ def test_order_query(admin_api_client, fulfilled_order, shipping_zone):
assert order_data['userEmail'] == order.user_email
expected_price = order_data['shippingPrice']['gross']['amount']
assert expected_price == order.shipping_price.gross.amount
- assert order_data['lines']['totalCount'] == order.lines.count()
+ assert len(order_data['lines']) == order.lines.count()
fulfillment = order.fulfillments.first().fulfillment_order
fulfillment_order = order_data['fulfillments'][0]['fulfillmentOrder']
assert fulfillment_order == fulfillment
@@ -241,13 +236,9 @@ def test_draft_order_create(
}
discountName
lines {
- edges {
- node {
- productName
- productSku
- quantity
- }
- }
+ productName
+ productSku
+ quantity
}
status
voucher {