Skip to content

Commit 4a31f4f

Browse files
committed
magento/graphql-ce#41: get user info from resolver context
1 parent 584eb7d commit 4a31f4f

File tree

2 files changed

+18
-34
lines changed
  • app/code/Magento/SalesGraphQl/Model/Resolver
  • dev/tests/api-functional/testsuite/Magento/GraphQl/Sales

2 files changed

+18
-34
lines changed

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,10 @@
1515
use Magento\CustomerGraphQl\Model\Customer\CheckCustomerAccountInterface;
1616

1717
/**
18-
* {@inheritdoc}
18+
* Class Orders
1919
*/
2020
class Orders implements ResolverInterface
2121
{
22-
/**
23-
* @var UserContextInterface
24-
*/
25-
private $userContext;
26-
2722
/**
2823
* @var CollectionFactoryInterface
2924
*/
@@ -36,15 +31,13 @@ class Orders implements ResolverInterface
3631

3732
/**
3833
* Orders constructor.
39-
* @param UserContextInterface $userContext
4034
* @param CollectionFactoryInterface $collectionFactory
35+
* @param CheckCustomerAccountInterface $checkCustomerAccount
4136
*/
4237
public function __construct(
43-
UserContextInterface $userContext,
4438
CollectionFactoryInterface $collectionFactory,
4539
CheckCustomerAccountInterface $checkCustomerAccount
4640
) {
47-
$this->userContext = $userContext;
4841
$this->collectionFactory = $collectionFactory;
4942
$this->checkCustomerAccount = $checkCustomerAccount;
5043

@@ -55,18 +48,17 @@ public function __construct(
5548
*/
5649
public function resolve(
5750
Field $field,
58-
$context,
59-
ResolveInfo $info,
60-
array $value = null,
61-
array $args = null
51+
$context,
52+
ResolveInfo $info,
53+
array $value = null,
54+
array $args = null
6255
) {
56+
$customerId = $context->getUserId();
6357

64-
$customerId = $this->userContext->getUserId();
58+
$this->checkCustomerAccount->execute($customerId, $context->getUserType());
6559

66-
$this->checkCustomerAccount->execute($customerId, $this->userContext->getUserType());
67-
68-
$orders = $this->collectionFactory->create($customerId);
6960
$items = [];
61+
$orders = $this->collectionFactory->create($customerId);
7062

7163
/** @var \Magento\Sales\Model\Order $order */
7264
foreach ($orders as $order) {
@@ -75,11 +67,10 @@ public function resolve(
7567
'increment_id' => $order->getIncrementId(),
7668
'created_at' => $order->getCreatedAt(),
7769
'grand_total' => $order->getGrandTotal(),
78-
'state' => $order->getState(),
7970
'status' => $order->getStatus()
8071
];
8172
}
8273

8374
return ['items' => $items];
8475
}
85-
}
76+
}

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,15 @@ public function testOrdersQuery()
4040
$query =
4141
<<<QUERY
4242
query {
43-
customerOrders {
44-
items {
45-
id
46-
increment_id
47-
created_at
48-
grant_total
49-
state
50-
status
51-
}
43+
customerOrders {
44+
items {
45+
id
46+
increment_id
47+
created_at
48+
grand_total
49+
status
5250
}
51+
}
5352
}
5453
QUERY;
5554

@@ -61,31 +60,26 @@ public function testOrdersQuery()
6160
$expectedData = [
6261
[
6362
'increment_id' => '100000002',
64-
'state' => \Magento\Sales\Model\Order::STATE_NEW,
6563
'status' => 'processing',
6664
'grand_total' => 120.00
6765
],
6866
[
6967
'increment_id' => '100000003',
70-
'state' => \Magento\Sales\Model\Order::STATE_PROCESSING,
7168
'status' => 'processing',
7269
'grand_total' => 130.00
7370
],
7471
[
7572
'increment_id' => '100000004',
76-
'state' => \Magento\Sales\Model\Order::STATE_PROCESSING,
7773
'status' => 'closed',
7874
'grand_total' => 140.00
7975
],
8076
[
8177
'increment_id' => '100000005',
82-
'state' => \Magento\Sales\Model\Order::STATE_COMPLETE,
8378
'status' => 'complete',
8479
'grand_total' => 150.00
8580
],
8681
[
8782
'increment_id' => '100000006',
88-
'state' => \Magento\Sales\Model\Order::STATE_COMPLETE,
8983
'status' => 'complete',
9084
'grand_total' => 160.00
9185
]
@@ -96,7 +90,6 @@ public function testOrdersQuery()
9690
foreach ($expectedData as $key => $data) {
9791
$this->assertEquals($data['increment_id'], $actualData[$key]['increment_id']);
9892
$this->assertEquals($data['grand_total'], $actualData[$key]['grand_total']);
99-
$this->assertEquals($data['state'], $actualData[$key]['state']);
10093
$this->assertEquals($data['status'], $actualData[$key]['status']);
10194
}
10295
}

0 commit comments

Comments
 (0)