Skip to content

Commit 9a2fc6a

Browse files
committed
MC-20636: Order Details : Order Details by Order Number
- fix static
1 parent a8ffede commit 9a2fc6a

File tree

8 files changed

+56
-106
lines changed

8 files changed

+56
-106
lines changed

app/code/Magento/SalesGraphQl/Model/Resolver/CustomerOrders.php

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function __construct(
5656
}
5757

5858
/**
59-
* @inheritdoc
59+
* @inheritDoc
6060
*/
6161
public function resolve(
6262
Field $field,
@@ -77,59 +77,68 @@ public function resolve(
7777
$userId = $context->getUserId();
7878
/** @var StoreInterface $store */
7979
$store = $context->getExtensionAttributes()->getStore();
80-
try {
81-
$filterGroups = $this->orderFilter->createFilterGroups($args, $userId, (int)$store->getId());
82-
$this->searchCriteriaBuilder->setFilterGroups($filterGroups);
83-
if (isset($args['currentPage'])) {
84-
$this->searchCriteriaBuilder->setCurrentPage($args['currentPage']);
85-
}
86-
if (isset($args['pageSize'])) {
87-
$this->searchCriteriaBuilder->setPageSize($args['pageSize']);
88-
}
89-
90-
$searchCriteria = $this->searchCriteriaBuilder->create();
91-
$searchResult = $this->orderRepository->getList($searchCriteria);
92-
$orderArray = [];
93-
/** @var OrderInterface $order */
94-
foreach ($searchResult->getItems() as $key => $order) {
95-
$orderArray[$key] = $order->getData();
96-
$orderArray[$key]['model'] = $order;
97-
}
9880

81+
try {
82+
$searchResult = $this->getSearchResult($args, (int) $userId, (int)$store->getId());
9983
$maxPages = (int)ceil($searchResult->getTotalCount() / $searchResult->getPageSize());
10084
} catch (InputException $e) {
10185
throw new GraphQlInputException(__($e->getMessage()));
10286
}
10387

104-
$orders = [];
105-
foreach ($orderArray as $order) {
106-
if (!($order['model'] ?? null instanceof OrderInterface)) {
107-
throw new LocalizedException(__('"model" value should be specified'));
108-
}
109-
/** @var OrderInterface $orderModel */
110-
$orderModel = $order['model'];
111-
$orders[] = [
112-
'created_at' => $order['created_at'],
113-
'grand_total' => $order['grand_total'],
114-
'id' => base64_encode($order['entity_id']),
115-
'increment_id' => $order['increment_id'],
116-
'number' => $order['increment_id'],
117-
'order_date' => $order['created_at'],
118-
'order_number' => $order['increment_id'],
119-
'status' => $orderModel->getStatusLabel(),
120-
'shipping_method' => $orderModel->getShippingDescription(),
121-
'model' => $orderModel,
122-
];
123-
}
124-
12588
return [
12689
'total_count' => $searchResult->getTotalCount(),
127-
'items' => $orders,
90+
'items' => $this->formatOrdersArray($searchResult->getItems()),
12891
'page_info' => [
12992
'page_size' => $searchResult->getPageSize(),
13093
'current_page' => $searchResult->getCurPage(),
13194
'total_pages' => $maxPages,
13295
]
13396
];
13497
}
98+
99+
/**
100+
* Format order models for graphql schema
101+
*
102+
* @param OrderInterface[] $orderModels
103+
* @return array
104+
*/
105+
private function formatOrdersArray(array $orderModels) {
106+
$ordersArray = [];
107+
foreach ($orderModels as $orderModel) {
108+
$ordersArray[] = [
109+
'created_at' => $orderModel->getCreatedAt(),
110+
'grand_total' => $orderModel->getGrandTotal(),
111+
'id' => base64_encode($orderModel->getEntityId()),
112+
'increment_id' => $orderModel->getIncrementId(),
113+
'number' => $orderModel->getIncrementId(),
114+
'order_date' => $orderModel->getCreatedAt(),
115+
'order_number' => $orderModel->getIncrementId(),
116+
'status' => $orderModel->getStatusLabel(),
117+
'shipping_method' => $orderModel->getShippingDescription(),
118+
'model' => $orderModel,
119+
];
120+
}
121+
return $ordersArray;
122+
}
123+
124+
/**
125+
* Get search result from graphql query arguments
126+
*
127+
* @param array $args
128+
* @param int $userId
129+
* @param int $storeId
130+
* @return \Magento\Sales\Api\Data\OrderSearchResultInterface
131+
* @throws InputException
132+
*/
133+
private function getSearchResult(array $args, int $userId, int $storeId) {
134+
$filterGroups = $this->orderFilter->createFilterGroups($args, $userId, (int)$storeId);
135+
$this->searchCriteriaBuilder->setFilterGroups($filterGroups);
136+
if (isset($args['currentPage'])) {
137+
$this->searchCriteriaBuilder->setCurrentPage($args['currentPage']);
138+
}
139+
if (isset($args['pageSize'])) {
140+
$this->searchCriteriaBuilder->setPageSize($args['pageSize']);
141+
}
142+
return $this->orderRepository->getList($this->searchCriteriaBuilder->create());
143+
}
135144
}

app/code/Magento/SalesGraphQl/Model/Resolver/InvoiceItems.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct(
4646
}
4747

4848
/**
49-
* @inheritdoc
49+
* @inheritDoc
5050
*/
5151
public function resolve(
5252
Field $field,

app/code/Magento/SalesGraphQl/Model/Resolver/InvoiceTotal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class InvoiceTotal implements ResolverInterface
2121
{
2222
/**
23-
* @inheritdoc
23+
* @inheritDoc
2424
*/
2525
public function resolve(
2626
Field $field,

app/code/Magento/SalesGraphQl/Model/Resolver/Invoices.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class Invoices implements ResolverInterface
2121
{
2222
/**
23-
* @inheritdoc
23+
* @inheritDoc
2424
*/
2525
public function resolve(
2626
Field $field,

app/code/Magento/SalesGraphQl/Model/Resolver/OrderTotal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
class OrderTotal implements ResolverInterface
1818
{
1919
/**
20-
* @inheritdoc
20+
* @inheritDoc
2121
*/
2222
public function resolve(
2323
Field $field,

app/code/Magento/SalesGraphQl/Model/Resolver/Orders.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(
3535
}
3636

3737
/**
38-
* @inheritdoc
38+
* @inheritDoc
3939
*/
4040
public function resolve(
4141
Field $field,

app/code/Magento/SalesGraphQl/Model/Resolver/Reorder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct(
4949
}
5050

5151
/**
52-
* @inheritdoc
52+
* @inheritDoc
5353
*/
5454
public function resolve(
5555
Field $field,

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

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -485,65 +485,6 @@ private function placeOrder(string $cartId): string
485485
return $response['placeOrder']['order']['order_number'];
486486
}
487487

488-
/**
489-
* Get customer order query
490-
*
491-
* @param string $orderNumber
492-
* @return array
493-
*/
494-
private function getCustomerOrderQuery($orderNumber):array
495-
{
496-
$query =
497-
<<<QUERY
498-
{
499-
customer {
500-
email
501-
orders(filter:{number:{eq:"{$orderNumber}"}}) {
502-
total_count
503-
items {
504-
id
505-
number
506-
order_date
507-
status
508-
items{product_name product_sku quantity_ordered discounts {amount{value currency} label}}
509-
total {
510-
base_grand_total{value currency}
511-
grand_total{value currency}
512-
total_tax{value}
513-
subtotal { value currency }
514-
taxes {amount{value currency} title rate}
515-
discounts {amount{value currency} label}
516-
total_shipping{value}
517-
shipping_handling
518-
{
519-
amount_including_tax{value}
520-
amount_excluding_tax{value}
521-
total_amount{value currency}
522-
taxes {amount{value} title rate}
523-
discounts {amount{value currency} label}
524-
}
525-
526-
}
527-
}
528-
}
529-
}
530-
}
531-
QUERY;
532-
$currentEmail = '[email protected]';
533-
$currentPassword = 'password';
534-
$response = $this->graphQlQuery(
535-
$query,
536-
[],
537-
'',
538-
$this->customerAuthenticationHeader->execute($currentEmail, $currentPassword)
539-
);
540-
541-
$this->assertArrayHasKey('orders', $response['customer']);
542-
$this->assertArrayHasKey('items', $response['customer']['orders']);
543-
$customerOrderItemsInResponse = $response['customer']['orders']['items'];
544-
return $customerOrderItemsInResponse;
545-
}
546-
547488
/**
548489
* Get customer order query for bundle order items
549490
*

0 commit comments

Comments
 (0)