Skip to content

Commit 5957630

Browse files
author
Krishna Kumar
committed
Suggestions mentioned by Rogyar V1
1 parent 517dc29 commit 5957630

File tree

4 files changed

+14
-26
lines changed

4 files changed

+14
-26
lines changed

app/code/Magento/LoginAsCustomerGraphQl/Model/LoginAsCustomer/CreateCustomerToken.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Framework\Exception\LocalizedException;
1212
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1313
use Magento\Integration\Model\Oauth\TokenFactory;
14-
use Magento\Store\Model\StoreManagerInterface;
14+
use Magento\Store\Api\Data\StoreInterface;
1515
use Exception;
1616

1717
/**
@@ -31,23 +31,15 @@ class CreateCustomerToken
3131
*/
3232
private $tokenModelFactory;
3333

34-
/**
35-
* @var StoreManagerInterface
36-
*/
37-
private $storeManager;
38-
3934
/**
4035
* CreateCustomerToken constructor.
41-
* @param StoreManagerInterface $storeManager
4236
* @param TokenFactory $tokenModelFactory
4337
* @param CustomerFactory $customerFactory
4438
*/
4539
public function __construct(
46-
StoreManagerInterface $storeManager,
4740
TokenFactory $tokenModelFactory,
4841
CustomerFactory $customerFactory
4942
) {
50-
$this->storeManager = $storeManager;
5143
$this->tokenModelFactory = $tokenModelFactory;
5244
$this->customerFactory= $customerFactory;
5345
}
@@ -56,14 +48,14 @@ public function __construct(
5648
* Get admin user token
5749
*
5850
* @param string $email
51+
* @param StoreInterface $store
5952
* @return array
53+
* @throws GraphQlInputException
6054
* @throws LocalizedException
6155
*/
62-
public function execute(string $email): array
56+
public function execute(string $email, StoreInterface $store): array
6357
{
64-
$websiteID = $this->storeManager->getStore()->getWebsiteId();
65-
66-
$customer = $this->customerFactory->create()->setWebsiteId($websiteID)->loadByEmail($email);
58+
$customer = $this->customerFactory->create()->setWebsiteId((int)$store->getId())->loadByEmail($email);
6759

6860
/* Check if customer email exist */
6961
if (!$customer->getId()) {

app/code/Magento/LoginAsCustomerGraphQl/Model/Resolver/RequestCustomerToken.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ public function resolve(
8181

8282
/* Get input params */
8383
try {
84-
$args = $args['input'] ?: [];
84+
$args = $args['input'];
8585
} catch (NoSuchEntityException $e) {
86-
throw new GraphQlNoSuchEntityException(__('Check input params.'));
86+
throw new GraphQlInputException(__('Check input params.'));
8787
}
8888

8989
if (empty(trim($args['customer_email'], " "))) {
@@ -97,8 +97,10 @@ public function resolve(
9797
__('Login as Customer is disabled.')
9898
);
9999
}
100-
101-
return $this->createCustomerToken->execute($args['customer_email']);
100+
return $this->createCustomerToken->execute(
101+
$args['customer_email'],
102+
$context->getExtensionAttributes()->getStore()
103+
);
102104
}
103105

104106
/**

app/code/Magento/LoginAsCustomerGraphQl/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"magento/module-integration": "*",
99
"magento/module-store": "*",
1010
"magento/module-customer": "*",
11-
"magento/module-catalog-graph-ql": "*",
12-
"magento/framework": "*"
11+
"magento/module-catalog-graph-ql": "*"
1312
},
1413
"type": "magento2-module",
1514
"license": [

dev/tests/api-functional/testsuite/Magento/GraphQl/LoginAsCustomer/GenerateLoginCustomerTokenTest.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ public function testGenerateCustomerValidTokenLoginAsCustomerDisabled()
8484
'',
8585
$this->getAdminHeaderAuthentication('TestAdmin1', 'Zilker777')
8686
);
87-
$this->assertArrayHasKey('generateCustomerTokenAsAdmin', $response);
88-
$this->assertIsArray($response['generateCustomerTokenAsAdmin']);
8987
}
9088

9189
/**
@@ -105,14 +103,12 @@ public function testGenerateCustomerTokenLoginWithCustomerCredentials()
105103

106104
$mutation = $this->getQuery($customerEmail);
107105

108-
$response = $this->graphQlMutation(
106+
$this->graphQlMutation(
109107
$mutation,
110108
[],
111109
'',
112110
$this->getCustomerHeaderAuthentication($customerEmail, $password)
113111
);
114-
$this->assertArrayHasKey('generateCustomerTokenAsAdmin', $response);
115-
$this->assertIsArray($response['generateCustomerTokenAsAdmin']);
116112
}
117113

118114
/**
@@ -137,7 +133,7 @@ public function testGenerateCustomerTokenInvalidData(
137133
$this->expectExceptionMessage($message);
138134

139135
$mutation = $this->getQuery($customerEmail);
140-
$response = $this->graphQlMutation(
136+
$this->graphQlMutation(
141137
$mutation,
142138
[],
143139
'',
@@ -218,7 +214,6 @@ private function getAdminHeaderAuthentication(string $userName, string $password
218214
{
219215
try {
220216
$adminAccessToken = $this->adminTokenService->createAdminAccessToken($userName, $password);
221-
222217
return ['Authorization' => 'Bearer ' . $adminAccessToken];
223218
} catch (\Exception $e) {
224219
throw new AuthenticationException(

0 commit comments

Comments
 (0)