Skip to content

Commit d92bf18

Browse files
authored
ENGCOM-5817: Added createCustomerGraphQl plugin #763
2 parents 79cc8d1 + c8553e4 commit d92bf18

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1414
use Magento\Framework\GraphQl\Query\ResolverInterface;
1515
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
16+
use Magento\Newsletter\Model\Config;
17+
use Magento\Store\Model\ScopeInterface;
1618

1719
/**
1820
* Create customer account resolver
@@ -30,13 +32,23 @@ class CreateCustomer implements ResolverInterface
3032
private $createCustomerAccount;
3133

3234
/**
35+
* @var Config
36+
*/
37+
private $newsLetterConfig;
38+
39+
/**
40+
* CreateCustomer constructor.
41+
*
3342
* @param ExtractCustomerData $extractCustomerData
3443
* @param CreateCustomerAccount $createCustomerAccount
44+
* @param Config $newsLetterConfig
3545
*/
3646
public function __construct(
3747
ExtractCustomerData $extractCustomerData,
38-
CreateCustomerAccount $createCustomerAccount
48+
CreateCustomerAccount $createCustomerAccount,
49+
Config $newsLetterConfig
3950
) {
51+
$this->newsLetterConfig = $newsLetterConfig;
4052
$this->extractCustomerData = $extractCustomerData;
4153
$this->createCustomerAccount = $createCustomerAccount;
4254
}
@@ -55,6 +67,10 @@ public function resolve(
5567
throw new GraphQlInputException(__('"input" value should be specified'));
5668
}
5769

70+
if (!$this->newsLetterConfig->isActive(ScopeInterface::SCOPE_STORE)) {
71+
$args['input']['is_subscribed'] = false;
72+
}
73+
5874
$customer = $this->createCustomerAccount->execute(
5975
$args['input'],
6076
$context->getExtensionAttributes()->getStore()

app/code/Magento/Newsletter/Test/Unit/Observer/PredispatchNewsletterObserverTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ public function testNewsletterDisabled() : void
121121
->willReturn(false);
122122

123123
$expectedRedirectUrl = 'https://test.com/index';
124-
125124
$this->configMock->expects($this->once())
126125
->method('getValue')
127126
->with('web/default/no_route', ScopeInterface::SCOPE_STORE)

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ public function testCreateCustomerIfNameEmpty()
251251
$newFirstname = '';
252252
$newLastname = 'Rowe';
253253
$currentPassword = 'test123#';
254-
255254
$query = <<<QUERY
256255
mutation {
257256
createCustomer(
@@ -275,6 +274,38 @@ public function testCreateCustomerIfNameEmpty()
275274
QUERY;
276275
$this->graphQlMutation($query);
277276
}
277+
278+
/**
279+
* @magentoConfigFixture default_store newsletter/general/active 0
280+
*/
281+
public function testCreateCustomerSubscribed()
282+
{
283+
$newFirstname = 'Richard';
284+
$newLastname = 'Rowe';
285+
$newEmail = 'new_customer@example.com';
286+
287+
$query = <<<QUERY
288+
mutation {
289+
createCustomer(
290+
input: {
291+
firstname: "{$newFirstname}"
292+
lastname: "{$newLastname}"
293+
email: "{$newEmail}"
294+
is_subscribed: true
295+
}
296+
) {
297+
customer {
298+
email
299+
is_subscribed
300+
}
301+
}
302+
}
303+
QUERY;
304+
305+
$response = $this->graphQlMutation($query);
306+
307+
$this->assertEquals(false, $response['createCustomer']['customer']['is_subscribed']);
308+
}
278309

279310
public function tearDown()
280311
{

0 commit comments

Comments
 (0)