Skip to content

Commit 9febc16

Browse files
committed
Merge remote-tracking branch 'oleksandr/29479_returns_graphql_implementation_new' into HB-PR-delivery-Nov
2 parents f3b2743 + ee34db9 commit 9febc16

File tree

6 files changed

+211
-52
lines changed

6 files changed

+211
-52
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Eav\Model\ResourceModel\Entity\Attribute;
10+
11+
use Magento\Framework\App\ResourceConnection;
12+
use Magento\Framework\DB\Adapter\AdapterInterface;
13+
14+
/**
15+
* Provide option value
16+
*/
17+
class OptionValueProvider
18+
{
19+
/**
20+
* @var AdapterInterface
21+
*/
22+
private $connection;
23+
24+
/**
25+
* @param ResourceConnection $connection
26+
*/
27+
public function __construct(ResourceConnection $connection)
28+
{
29+
$this->connection = $connection->getConnection();
30+
}
31+
32+
/**
33+
* Get EAV attribute option value by option id
34+
*
35+
* @param int $valueId
36+
* @return string|null
37+
*/
38+
public function get(int $valueId): ?string
39+
{
40+
$select = $this->connection->select()
41+
->from($this->connection->getTableName('eav_attribute_option_value'), 'value')
42+
->where('value_id = ?', $valueId);
43+
44+
$result = $this->connection->fetchOne($select);
45+
46+
if ($result !== false) {
47+
return $result;
48+
}
49+
50+
return null;
51+
}
52+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SalesGraphQl\Model\Formatter;
9+
10+
use Magento\Sales\Api\Data\OrderInterface;
11+
use Magento\SalesGraphQl\Model\Order\OrderAddress;
12+
use Magento\SalesGraphQl\Model\Order\OrderPayments;
13+
14+
/**
15+
* Format order model for graphql schema
16+
*/
17+
class Order
18+
{
19+
/**
20+
* @var OrderAddress
21+
*/
22+
private $orderAddress;
23+
24+
/**
25+
* @var OrderPayments
26+
*/
27+
private $orderPayments;
28+
29+
/**
30+
* @param OrderAddress $orderAddress
31+
* @param OrderPayments $orderPayments
32+
*/
33+
public function __construct(
34+
OrderAddress $orderAddress,
35+
OrderPayments $orderPayments
36+
) {
37+
$this->orderAddress = $orderAddress;
38+
$this->orderPayments = $orderPayments;
39+
}
40+
41+
/**
42+
* Format order model for graphql schema
43+
*
44+
* @param OrderInterface $orderModel
45+
* @return array
46+
*/
47+
public function format(OrderInterface $orderModel): array
48+
{
49+
return [
50+
'created_at' => $orderModel->getCreatedAt(),
51+
'grand_total' => $orderModel->getGrandTotal(),
52+
'id' => base64_encode($orderModel->getEntityId()),
53+
'increment_id' => $orderModel->getIncrementId(),
54+
'number' => $orderModel->getIncrementId(),
55+
'order_date' => $orderModel->getCreatedAt(),
56+
'order_number' => $orderModel->getIncrementId(),
57+
'status' => $orderModel->getStatusLabel(),
58+
'shipping_method' => $orderModel->getShippingDescription(),
59+
'shipping_address' => $this->orderAddress->getOrderShippingAddress($orderModel),
60+
'billing_address' => $this->orderAddress->getOrderBillingAddress($orderModel),
61+
'payment_methods' => $this->orderPayments->getOrderPaymentMethod($orderModel),
62+
'model' => $orderModel,
63+
];
64+
}
65+
}

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

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1515
use Magento\Framework\GraphQl\Query\ResolverInterface;
1616
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
17-
use Magento\Sales\Api\Data\OrderInterface;
1817
use Magento\Sales\Api\OrderRepositoryInterface;
19-
use Magento\SalesGraphQl\Model\Order\OrderAddress;
20-
use Magento\SalesGraphQl\Model\Order\OrderPayments;
18+
use Magento\SalesGraphQl\Model\Formatter\Order as OrderFormatter;
2119
use Magento\SalesGraphQl\Model\Resolver\CustomerOrders\Query\OrderFilter;
2220
use Magento\Store\Api\Data\StoreInterface;
2321

@@ -31,16 +29,6 @@ class CustomerOrders implements ResolverInterface
3129
*/
3230
private $searchCriteriaBuilder;
3331

34-
/**
35-
* @var OrderAddress
36-
*/
37-
private $orderAddress;
38-
39-
/**
40-
* @var OrderPayments
41-
*/
42-
private $orderPayments;
43-
4432
/**
4533
* @var OrderRepositoryInterface
4634
*/
@@ -51,25 +39,27 @@ class CustomerOrders implements ResolverInterface
5139
*/
5240
private $orderFilter;
5341

42+
/**
43+
* @var OrderFormatter
44+
*/
45+
private $orderFormatter;
46+
5447
/**
5548
* @param OrderRepositoryInterface $orderRepository
56-
* @param OrderAddress $orderAddress
57-
* @param OrderPayments $orderPayments
5849
* @param SearchCriteriaBuilder $searchCriteriaBuilder
5950
* @param OrderFilter $orderFilter
51+
* @param OrderFormatter $orderFormatter
6052
*/
6153
public function __construct(
6254
OrderRepositoryInterface $orderRepository,
63-
OrderAddress $orderAddress,
64-
OrderPayments $orderPayments,
6555
SearchCriteriaBuilder $searchCriteriaBuilder,
66-
OrderFilter $orderFilter
56+
OrderFilter $orderFilter,
57+
OrderFormatter $orderFormatter
6758
) {
6859
$this->orderRepository = $orderRepository;
69-
$this->orderAddress = $orderAddress;
70-
$this->orderPayments = $orderPayments;
7160
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
7261
$this->orderFilter = $orderFilter;
62+
$this->orderFormatter = $orderFormatter;
7363
}
7464

7565
/**
@@ -101,9 +91,14 @@ public function resolve(
10191
throw new GraphQlInputException(__($e->getMessage()));
10292
}
10393

94+
$ordersArray = [];
95+
foreach ($searchResult->getItems() as $orderModel) {
96+
$ordersArray[] = $this->orderFormatter->format($orderModel);
97+
}
98+
10499
return [
105100
'total_count' => $searchResult->getTotalCount(),
106-
'items' => $this->formatOrdersArray($searchResult->getItems()),
101+
'items' => $ordersArray,
107102
'page_info' => [
108103
'page_size' => $searchResult->getPageSize(),
109104
'current_page' => $searchResult->getCurPage(),
@@ -112,35 +107,6 @@ public function resolve(
112107
];
113108
}
114109

115-
/**
116-
* Format order models for graphql schema
117-
*
118-
* @param OrderInterface[] $orderModels
119-
* @return array
120-
*/
121-
private function formatOrdersArray(array $orderModels)
122-
{
123-
$ordersArray = [];
124-
foreach ($orderModels as $orderModel) {
125-
$ordersArray[] = [
126-
'created_at' => $orderModel->getCreatedAt(),
127-
'grand_total' => $orderModel->getGrandTotal(),
128-
'id' => base64_encode($orderModel->getEntityId()),
129-
'increment_id' => $orderModel->getIncrementId(),
130-
'number' => $orderModel->getIncrementId(),
131-
'order_date' => $orderModel->getCreatedAt(),
132-
'order_number' => $orderModel->getIncrementId(),
133-
'status' => $orderModel->getStatusLabel(),
134-
'shipping_method' => $orderModel->getShippingDescription(),
135-
'shipping_address' => $this->orderAddress->getOrderShippingAddress($orderModel),
136-
'billing_address' => $this->orderAddress->getOrderBillingAddress($orderModel),
137-
'payment_methods' => $this->orderPayments->getOrderPaymentMethod($orderModel),
138-
'model' => $orderModel,
139-
];
140-
}
141-
return $ordersArray;
142-
}
143-
144110
/**
145111
* Get search result from graphql query arguments
146112
*

app/code/Magento/Shipping/Model/Tracking/Result/Error.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@
55
*/
66
namespace Magento\Shipping\Model\Tracking\Result;
77

8-
class Error extends \Magento\Shipping\Model\Tracking\Result\AbstractResult
8+
use Magento\Framework\Phrase;
9+
10+
/**
11+
* Class to get data from error shipping tracking result
12+
*/
13+
class Error extends AbstractResult
914
{
15+
public const STATUS_TYPE = 1;
16+
1017
/**
18+
* Gets all data of shipping tracking result
19+
*
1120
* @return array
1221
*/
1322
public function getAllData()
@@ -16,7 +25,9 @@ public function getAllData()
1625
}
1726

1827
/**
19-
* @return \Magento\Framework\Phrase
28+
* Gets error message
29+
*
30+
* @return Phrase
2031
*/
2132
public function getErrorMessage()
2233
{

app/code/Magento/Shipping/Model/Tracking/Result/Status.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
class Status extends AbstractResult
2020
{
21+
public const STATUS_TYPE = 0;
22+
2123
/**
2224
* Returns all Status data
2325
*
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Framework\GraphQl\Query;
10+
11+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
12+
13+
/**
14+
* Encodes and decodes id and uid values
15+
*/
16+
class Uid
17+
{
18+
/**
19+
* Decode UID value to ID
20+
*
21+
* @param string $uid
22+
* @return null|string
23+
* @phpcs:disable Magento2.Functions.DiscouragedFunction
24+
* @throws GraphQlInputException
25+
*/
26+
public function decode(string $uid): ?string
27+
{
28+
if ($this->isValidBase64($uid)) {
29+
$result = base64_decode($uid, true);
30+
return ($result !== false) ? $result : null;
31+
}
32+
throw new GraphQlInputException(__('Value of uid "%1" is incorrect.', $uid));
33+
}
34+
35+
/**
36+
* Encode ID value to UID
37+
*
38+
* @param string $id
39+
* @return string
40+
* @phpcs:disable Magento2.Functions.DiscouragedFunction
41+
*/
42+
public function encode(string $id): string
43+
{
44+
return base64_encode($id);
45+
}
46+
47+
/**
48+
* Validate base64 encoded value
49+
*
50+
* @param string $data
51+
* @return bool
52+
* @phpcs:disable Magento2.Functions.DiscouragedFunction
53+
*/
54+
public function isValidBase64(string $data): bool
55+
{
56+
$decodedValue = base64_decode($data, true);
57+
if ($decodedValue === false) {
58+
return false;
59+
}
60+
61+
return base64_encode($decodedValue) === $data;
62+
}
63+
}

0 commit comments

Comments
 (0)