Skip to content

Commit a50e724

Browse files
sivaschenkosvera
authored andcommitted
LYNX-359: Added email field to CustomerOrder and fixed orderV2 error handling
1 parent 981ad32 commit a50e724

File tree

6 files changed

+20
-15
lines changed

6 files changed

+20
-15
lines changed

app/code/Magento/QuoteGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ type ApplyCouponToCartOutput @doc(description: "Contains details about the cart
260260

261261
type PlaceOrderOutput @doc(description: "Contains the results of the request to place an order.") {
262262
order: Order @deprecated(reason: "Use `orderV2` instead.") @doc(description: "The ID of the order.")
263-
orderV2: CustomerOrder! @doc(description: "Full order information.")
263+
orderV2: CustomerOrder @doc(description: "Full order information.")
264264
errors: [PlaceOrderError!]! @doc(description:"An array of place order errors.")
265265
}
266266

app/code/Magento/SalesGraphQl/Model/Formatter/Order.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,14 @@
1717
*/
1818
class Order
1919
{
20-
/**
21-
* @var OrderAddress
22-
*/
23-
private $orderAddress;
24-
25-
/**
26-
* @var OrderPayments
27-
*/
28-
private $orderPayments;
29-
3020
/**
3121
* @param OrderAddress $orderAddress
3222
* @param OrderPayments $orderPayments
3323
*/
3424
public function __construct(
35-
OrderAddress $orderAddress,
36-
OrderPayments $orderPayments
25+
private readonly OrderAddress $orderAddress,
26+
private readonly OrderPayments $orderPayments
3727
) {
38-
$this->orderAddress = $orderAddress;
39-
$this->orderPayments = $orderPayments;
4028
}
4129

4230
/**
@@ -57,6 +45,7 @@ public function format(OrderInterface $orderModel): array
5745
'order_date' => $orderModel->getCreatedAt(),
5846
'order_number' => $orderModel->getIncrementId(),
5947
'status' => $orderModel->getStatusLabel(),
48+
'email' => $orderModel->getCustomerEmail(),
6049
'shipping_method' => $orderModel->getShippingDescription(),
6150
'shipping_address' => $this->orderAddress->getOrderShippingAddress($orderModel),
6251
'billing_address' => $this->orderAddress->getOrderBillingAddress($orderModel),

app/code/Magento/SalesGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ type CustomerOrder @doc(description: "Contains details about each of the custome
7474
grand_total: Float @deprecated(reason: "Use the `totals.grand_total` field instead.")
7575
token: String! @doc(description: "The token that can be used to retrieve the order using order query.") @resolver(class: "Magento\\SalesGraphQl\\Model\\Resolver\\Token")
7676
applied_coupons: [AppliedCoupon!]! @doc(description: "Coupons applied to the order.")
77+
email: String @doc(description: "Order customer email.")
7778
}
7879

7980
type OrderAddress @doc(description: "Contains detailed information about an order's billing and shipping addresses."){

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/PlaceOrderTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ public function testPlaceOrder()
109109

110110
self::assertArrayHasKey('placeOrder', $response);
111111
self::assertArrayHasKey('order_number', $response['placeOrder']['order']);
112+
self::assertArrayHasKey('number', $response['placeOrder']['orderV2']);
112113
self::assertEquals($reservedOrderId, $response['placeOrder']['order']['order_number']);
114+
self::assertEquals($reservedOrderId, $response['placeOrder']['orderV2']['number']);
113115
self::assertEmpty(count($response['placeOrder']['errors']));
114116
$orderIncrementId = $response['placeOrder']['order']['order_number'];
115117
$order = $this->orderFactory->create();
@@ -147,7 +149,9 @@ public function testPlaceOrderWithAutoGroup()
147149

148150
self::assertArrayHasKey('placeOrder', $response);
149151
self::assertArrayHasKey('order_number', $response['placeOrder']['order']);
152+
self::assertArrayHasKey('number', $response['placeOrder']['orderV2']);
150153
self::assertEquals($reservedOrderId, $response['placeOrder']['order']['order_number']);
154+
self::assertEquals($reservedOrderId, $response['placeOrder']['orderV2']['number']);
151155
self::assertEmpty(count($response['placeOrder']['errors']));
152156
$orderIncrementId = $response['placeOrder']['order']['order_number'];
153157
$order = $this->orderFactory->create();
@@ -458,7 +462,9 @@ public function testPlaceOrderWithGiftMessage()
458462

459463
self::assertArrayHasKey('placeOrder', $response);
460464
self::assertArrayHasKey('order_number', $response['placeOrder']['order']);
465+
self::assertArrayHasKey('number', $response['placeOrder']['orderV2']);
461466
self::assertEquals($reservedOrderId, $response['placeOrder']['order']['order_number']);
467+
self::assertEquals($reservedOrderId, $response['placeOrder']['orderV2']['number']);
462468
$orderIncrementId = $response['placeOrder']['order']['order_number'];
463469
$order = $this->orderFactory->create();
464470
$order->loadByIncrementId($orderIncrementId);
@@ -477,6 +483,9 @@ private function getQuery(string $maskedQuoteId): string
477483
order {
478484
order_number
479485
}
486+
orderV2 {
487+
number
488+
}
480489
errors {
481490
message
482491
code

dev/tests/api-functional/testsuite/Magento/GraphQl/Sales/GuestOrderByTokenTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class GuestOrderByTokenTest extends GraphQlAbstract
4848
token: "%token"
4949
}) {
5050
number
51+
email
5152
billing_address {
5253
firstname
5354
lastname
@@ -63,6 +64,7 @@ class GuestOrderByTokenTest extends GraphQlAbstract
6364
}) {
6465
orderV2 {
6566
number
67+
email
6668
billing_address {
6769
firstname
6870
lastname
@@ -97,6 +99,7 @@ public function testGuestOrder(): void
9799

98100
$this->assertNotEmpty($placeOrderResponse['placeOrder']['orderV2']['number']);
99101
$this->assertNotEmpty($placeOrderResponse['placeOrder']['orderV2']['token']);
102+
$this->assertNotEmpty($placeOrderResponse['placeOrder']['orderV2']['email']);
100103
$this->assertNotEmpty($placeOrderResponse['placeOrder']['orderV2']['billing_address']['firstname']);
101104
$this->assertNotEmpty($placeOrderResponse['placeOrder']['orderV2']['billing_address']['lastname']);
102105

@@ -111,6 +114,7 @@ public function testGuestOrder(): void
111114
[
112115
'guestOrderByToken' => [
113116
'number' => $placeOrderResponse['placeOrder']['orderV2']['number'],
117+
'email' => $placeOrderResponse['placeOrder']['orderV2']['email'],
114118
'billing_address' => [
115119
'firstname' => $placeOrderResponse['placeOrder']['orderV2']['billing_address']['firstname'],
116120
'lastname' => $placeOrderResponse['placeOrder']['orderV2']['billing_address']['lastname']

dev/tests/api-functional/testsuite/Magento/GraphQl/Sales/GuestOrderTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class GuestOrderTest extends GraphQlAbstract
4747
postcode: "%postcode"
4848
}) {
4949
number
50+
email
5051
billing_address {
5152
firstname
5253
lastname
@@ -83,6 +84,7 @@ public function testGuestOrder(): void
8384
[
8485
'guestOrder' => [
8586
'number' => $order->getIncrementId(),
87+
'email' => $order->getBillingAddress()->getEmail(),
8688
'billing_address' => [
8789
'firstname' => $order->getBillingAddress()->getFirstname(),
8890
'lastname' => $order->getBillingAddress()->getLastname()

0 commit comments

Comments
 (0)