diff --git a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php index 1f730f2a5c7e..6d33dea35835 100644 --- a/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php +++ b/app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php @@ -13,6 +13,8 @@ use Magento\Framework\GraphQl\Exception\GraphQlInputException; use Magento\Framework\GraphQl\Query\ResolverInterface; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; +use Magento\Newsletter\Model\Config; +use Magento\Store\Model\ScopeInterface; /** * Create customer account resolver @@ -30,13 +32,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; } @@ -55,6 +67,10 @@ public function resolve( throw new GraphQlInputException(__('"input" value should be specified')); } + if (!$this->newsLetterConfig->isActive(ScopeInterface::SCOPE_STORE)) { + $args['input']['is_subscribed'] = false; + } + $customer = $this->createCustomerAccount->execute( $args['input'], $context->getExtensionAttributes()->getStore() diff --git a/app/code/Magento/Newsletter/Test/Unit/Observer/PredispatchNewsletterObserverTest.php b/app/code/Magento/Newsletter/Test/Unit/Observer/PredispatchNewsletterObserverTest.php index 9b02f60765fb..6846231319d6 100644 --- a/app/code/Magento/Newsletter/Test/Unit/Observer/PredispatchNewsletterObserverTest.php +++ b/app/code/Magento/Newsletter/Test/Unit/Observer/PredispatchNewsletterObserverTest.php @@ -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) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php index 67c21a3798a5..c5714012f38c 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/CreateCustomerTest.php @@ -251,7 +251,6 @@ public function testCreateCustomerIfNameEmpty() $newFirstname = ''; $newLastname = 'Rowe'; $currentPassword = 'test123#'; - $query = <<graphQlMutation($query); } + + /** + * @magentoConfigFixture default_store newsletter/general/active 0 + */ + public function testCreateCustomerSubscribed() + { + $newFirstname = 'Richard'; + $newLastname = 'Rowe'; + $newEmail = 'new_customer@example.com'; + + $query = <<graphQlMutation($query); + + $this->assertEquals(false, $response['createCustomer']['customer']['is_subscribed']); + } public function tearDown() {