Skip to content

Commit 11ab599

Browse files
committed
MC-35653:MyAccount :: Order Details :: Payments Methods, shipping address, billing address by Order Number
- Added test assertions
1 parent c792758 commit 11ab599

File tree

3 files changed

+95
-41
lines changed

3 files changed

+95
-41
lines changed

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77

88
namespace Magento\SalesGraphQl\Model\Order;
99

10-
use Magento\Quote\Model\Quote\Address;
1110
use Magento\Sales\Api\Data\OrderAddressInterface;
1211
use Magento\Sales\Api\Data\OrderInterface;
1312

1413
/**
15-
* Class to fetch the order address details
14+
* Class to get the order address details
1615
*/
1716
class OrderAddress
1817
{
@@ -26,11 +25,8 @@ public function getOrderShippingAddress(
2625
OrderInterface $order
2726
) {
2827
$shippingAddress = null;
29-
$orderShippingAddress = $order->getShippingAddress() ?? null;
30-
if ($orderShippingAddress) {
31-
if ($orderShippingAddress->getAddressType() === ADDRESS::TYPE_SHIPPING) {
32-
$shippingAddress = $this->OrderAddressDataFormatter($orderShippingAddress);
33-
}
28+
if ($order->getShippingAddress()) {
29+
$shippingAddress = $this->OrderAddressDataFormatter($order->getShippingAddress());
3430
}
3531
return $shippingAddress;
3632
}
@@ -45,11 +41,8 @@ public function getOrderBillingAddress(
4541
OrderInterface $order
4642
) {
4743
$billingAddress = null;
48-
$orderBillingAddress = $order->getBillingAddress() ?? null;
49-
if ($orderBillingAddress) {
50-
if ($orderBillingAddress->getAddressType() === ADDRESS::TYPE_BILLING) {
51-
$billingAddress = $this->OrderAddressDataFormatter($orderBillingAddress);
52-
}
44+
if ($order->getBillingAddress()) {
45+
$billingAddress = $this->OrderAddressDataFormatter($order->getBillingAddress());
5346
}
5447
return $billingAddress;
5548
}

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

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Sales\Api\Data\OrderInterface;
1111

1212
/**
13-
* Class to fetch the order payment details
13+
* Class to get the order payment details
1414
*/
1515
class OrderPayments
1616
{
@@ -21,37 +21,11 @@ class OrderPayments
2121
public function getOrderPaymentMethod(OrderInterface $orderModel): array
2222
{
2323
$orderPayment = $orderModel->getPayment();
24-
$paymentAdditionalInfo = $orderModel->getExtensionAttributes()->getPaymentAdditionalInfo();
25-
$paymentAdditionalData = [];
26-
foreach ($paymentAdditionalInfo as $key => $paymentAdditionalInfoDetails) {
27-
$paymentAdditionalData[$key]['name'] = $paymentAdditionalInfoDetails->getKey();
28-
$paymentAdditionalData[$key]['value'] = $paymentAdditionalInfoDetails->getValue();
29-
}
30-
$additionalInformationCcType = $orderPayment->getCcType();
31-
$additionalInformationCcNumber = $orderPayment->getCcLast4();
32-
if ($orderPayment->getMethod() === 'checkmo' || $orderPayment->getMethod() === 'free' ||
33-
$orderPayment->getMethod() === 'purchaseorder' ||$orderPayment->getMethod() === 'cashondelivery' ||
34-
$orderPayment->getMethod() === 'banktransfer'
35-
) {
36-
$additionalData = [];
37-
} else {
38-
$additionalData = [
39-
[
40-
'name' => 'Credit Card Type',
41-
'value' => $additionalInformationCcType ?? null
42-
],
43-
[
44-
'name' => 'Credit Card Number',
45-
'value' => $additionalInformationCcNumber ?? null
46-
]
47-
];
48-
}
49-
5024
return [
5125
[
52-
'name' => $orderPayment->getAdditionalInformation()['method_title'] ?? null,
26+
'name' => $orderPayment->getAdditionalInformation()['method_title'] ?? 'method_title',
5327
'type' => $orderPayment->getMethod() ?? null,
54-
'additional_data' => $additionalData
28+
'additional_data' => []
5529
]
5630
];
5731
}

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

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public function testGetCustomerOrdersSimpleProductQuery()
6363
number
6464
status
6565
order_date
66+
payment_methods{name type additional_data{ name value}}
67+
shipping_address{firstname lastname city company country_code fax middlename postcode prefix street region
68+
region_id suffix telephone vat_id}
69+
billing_address{firstname lastname city company country_code fax middlename postcode prefix street region
70+
region_id suffix telephone vat_id}
6671
items{
6772
quantity_ordered
6873
product_sku
@@ -105,6 +110,9 @@ public function testGetCustomerOrdersSimpleProductQuery()
105110
$customerOrderItemsInResponse = $response['customer']['orders']['items'][0];
106111
$this->assertArrayHasKey('items', $customerOrderItemsInResponse);
107112
$this->assertNotEmpty($customerOrderItemsInResponse['items']);
113+
$this->assertNotEmpty($response["customer"]["orders"]["items"][0]["billing_address"]);
114+
$this->assertNotEmpty($response["customer"]["orders"]["items"][0]["shipping_address"]);
115+
$this->assertNotEmpty($response["customer"]["orders"]["items"][0]["payment_methods"]);
108116

109117
$searchCriteria = $this->searchCriteriaBuilder->addFilter('increment_id', '100000002')
110118
->create();
@@ -154,6 +162,9 @@ public function testCustomerOrdersSimpleProductWithTaxesAndDiscounts()
154162
$this->setPaymentMethod($cartId, $paymentMethod);
155163
$orderNumber = $this->placeOrder($cartId);
156164
$customerOrderResponse = $this->getCustomerOrderQuery($orderNumber);
165+
$this->assertOrderBillingAddress($customerOrderResponse[0]["billing_address"]);
166+
$this->assertOrderShippingAddress($customerOrderResponse[0]["shipping_address"]);
167+
$this->assertOrderPaymentMethod($customerOrderResponse[0]["payment_methods"]);
157168
// Asserting discounts on order item level
158169
$this->assertEquals(4, $customerOrderResponse[0]['items'][0]['discounts'][0]['amount']['value']);
159170
$this->assertEquals('USD', $customerOrderResponse[0]['items'][0]['discounts'][0]['amount']['currency']);
@@ -166,6 +177,77 @@ public function testCustomerOrdersSimpleProductWithTaxesAndDiscounts()
166177
$this->deleteOrder();
167178
}
168179

180+
/**
181+
* Check order billing address
182+
*
183+
* @param array $customerOrderBillingAddress
184+
*/
185+
private function assertOrderBillingAddress(array $customerOrderBillingAddress): void
186+
{
187+
$assertionMap = [
188+
'firstname' => 'John',
189+
'lastname' => 'Smith',
190+
'city' => 'Texas City',
191+
'company' => 'Test company',
192+
'country_code' => 'US',
193+
'postcode' => '78717',
194+
'prefix' => 'John',
195+
'region' => 'Texas',
196+
'region_id' => '57',
197+
'street' => [
198+
0 => 'test street 1',
199+
1 => 'test street 2',
200+
],
201+
'suffix' => 'John',
202+
'telephone' => '5123456677'
203+
];
204+
$this->assertResponseFields($customerOrderBillingAddress, $assertionMap);
205+
}
206+
207+
/**
208+
* Check order shipping address
209+
*
210+
* @param array $customerOrderShippingAddress
211+
*/
212+
private function assertOrderShippingAddress(array $customerOrderShippingAddress): void
213+
{
214+
$assertionMap = [
215+
'firstname' => 'test shipFirst',
216+
'lastname' => 'test shipLast',
217+
'city' => 'Montgomery',
218+
'company' => 'test company',
219+
'country_code' => 'US',
220+
'postcode' => '36013',
221+
'prefix' => 'test shipFirst',
222+
'street' => [
223+
0 => 'test street 1',
224+
1 => 'test street 2',
225+
],
226+
'region_id' => '1',
227+
'region' => 'Alabama',
228+
'suffix' => 'test shipFirst',
229+
'telephone' => '3347665522'
230+
];
231+
$this->assertResponseFields($customerOrderShippingAddress, $assertionMap);
232+
}
233+
234+
/**
235+
* Check order payment method
236+
*
237+
* @param array $customerOrderPaymentMethod
238+
*/
239+
private function assertOrderPaymentMethod(array $customerOrderPaymentMethod): void
240+
{
241+
$assertionMap = [
242+
[
243+
'name' => 'Check / Money order',
244+
'type' => 'checkmo',
245+
'additional_data' => []
246+
]
247+
];
248+
$this->assertResponseFields($customerOrderPaymentMethod, $assertionMap);
249+
}
250+
169251
/**
170252
* @param array $customerOrderItemTotal
171253
*/
@@ -1218,6 +1300,11 @@ private function getCustomerOrderQuery($orderNumber): array
12181300
number
12191301
order_date
12201302
status
1303+
payment_methods{name type additional_data{ name value}}
1304+
shipping_address{firstname lastname city company country_code fax middlename postcode prefix street region
1305+
region_id suffix telephone vat_id}
1306+
billing_address{firstname lastname city company country_code fax middlename postcode prefix street region
1307+
region_id suffix telephone vat_id}
12211308
items{product_name product_sku quantity_ordered discounts {amount{value currency} label}}
12221309
total {
12231310
base_grand_total{value currency}

0 commit comments

Comments
 (0)