Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Added createCustomerGraphQl plugin #763

Merged
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b31f618
Added createCustomerGraphQl plugin
sedonik Jul 5, 2019
51b433c
Moved logic from plugin to CreateCustomer
sedonik Jul 11, 2019
dfa329f
Added test method testCreateCustomerSubscribed
sedonik Jul 11, 2019
2ca7872
Added rollback for newsletter/general/active
sedonik Jul 12, 2019
c37a7a4
Added todo
sedonik Jul 12, 2019
c09c17e
Created Config Module for Newsletter
sedonik Jul 16, 2019
c646296
Deleted redundant dependency + set scopeType
sedonik Aug 6, 2019
02654a6
Added changes from PR #807
sedonik Aug 16, 2019
245e0a0
Merge branch '2.3-develop' into subscribe-for-newsletter
sedonik Aug 16, 2019
8b1e739
Corrected Code Style
sedonik Aug 20, 2019
6a4ecbe
Added lines *Deleted unnecessary uses
sedonik Aug 21, 2019
b4bdc73
Removed customer_subscribe.php and customer_subscribe_rollback.php
sedonik Aug 21, 2019
9cecea1
Update app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer…
sedonik Aug 28, 2019
68940ec
Renamed $config to $newsletterConfig
sedonik Aug 28, 2019
b88a3db
Renamed config to newsletterConfig
sedonik Aug 28, 2019
010536d
Renamed config to newsletterConfig
sedonik Aug 28, 2019
bf5d622
Renamed config to newsletterConfig
sedonik Aug 28, 2019
75e2408
Deleted empty line
sedonik Aug 28, 2019
c0caee9
Removed Exception
sedonik Aug 28, 2019
e99ddb8
Set magentoApiDataFixture
sedonik Aug 28, 2019
bfb57ec
Corrected newsLetterConfig
sedonik Aug 29, 2019
c35ac36
Corrected code styles
sedonik Aug 29, 2019
1e0db4d
Used @magentoConfigFixture + deleted customer_subscribe.php, customer…
sedonik Sep 2, 2019
dcd7178
Merge remote-tracking branch 'upstream/2.3-develop' into subscribe-fo…
sedonik Sep 6, 2019
0768d89
magento/graphql-ce#762: Subscribe for newsletter even when not allowed
lenaorobei Sep 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Newsletter\Model\Config;

/**
* Create customer account resolver
Expand All @@ -30,13 +31,23 @@ class CreateCustomer implements ResolverInterface
private $createCustomerAccount;

/**
* @var Config
*/
private $newsLetterConfig;

/**
* CreateCustomer constructor.
*
* @param ExtractCustomerData $extractCustomerData
* @param CreateCustomerAccount $createCustomerAccount
* @param Config $newsLetterConfig
*/
public function __construct(
ExtractCustomerData $extractCustomerData,
CreateCustomerAccount $createCustomerAccount
CreateCustomerAccount $createCustomerAccount,
Config $newsLetterConfig
) {
$this->newsLetterConfig = $newsLetterConfig;
$this->extractCustomerData = $extractCustomerData;
$this->createCustomerAccount = $createCustomerAccount;
}
Expand All @@ -55,6 +66,10 @@ public function resolve(
throw new GraphQlInputException(__('"input" value should be specified'));
}

if (!$this->newsLetterConfig->isActive()) {
$args['input']['is_subscribed'] = false;
}

$customer = $this->createCustomerAccount->execute(
$args['input'],
$context->getExtensionAttributes()->getStore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public function testNewsletterDisabled() : void
->willReturn(false);

$expectedRedirectUrl = 'https://test.com/index';

$this->configMock->expects($this->once())
->method('getValue')
->with('web/default/no_route', ScopeInterface::SCOPE_STORE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ public function testCreateCustomerIfNameEmpty()
$newFirstname = '';
$newLastname = 'Rowe';
$currentPassword = 'test123#';

$query = <<<QUERY
mutation {
createCustomer(
Expand All @@ -275,6 +274,38 @@ public function testCreateCustomerIfNameEmpty()
QUERY;
$this->graphQlMutation($query);
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer_subscribe.php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@magentoConfigFixture default_store newsletter/general/active 0

*/
public function testCreateCustomerSubscribed()
{
$newFirstname = 'Richard';
$newLastname = 'Rowe';
$newEmail = '[email protected]';

$query = <<<QUERY
mutation {
createCustomer(
input: {
firstname: "{$newFirstname}"
lastname: "{$newLastname}"
email: "{$newEmail}"
is_subscribed: true
}
) {
customer {
email
is_subscribed
}
}
}
QUERY;

$response = $this->graphQlMutation($query);

$this->assertEquals(false, $response['createCustomer']['customer']['is_subscribed']);
}

public function tearDown()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
lenaorobei marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be removed.

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this fixture please use @magentoApiDataFixture.

* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
$resourceConfig = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->create(\Magento\Config\Model\ResourceModel\Config::class);
$resourceConfig->saveConfig(
'newsletter/general/active',
false,
'default',
0
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should be removed.

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// TODO: Should be removed in scope of https://github.com/magento/graphql-ce/issues/167

declare(strict_types=1);

use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\TestFramework\Helper\Bootstrap;

$objectManager = Bootstrap::getObjectManager();
/** @var Writer $configWriter */
$configWriter = $objectManager->create(WriterInterface::class);
$configWriter->delete('newsletter/general/active');