Skip to content

Commit 0b282d1

Browse files
committed
Merge remote-tracking branch 'act4/ACP2E-3785' into PR_Apr23_doleksandr
2 parents 3927fbb + e4275fc commit 0b282d1

File tree

2 files changed

+73
-6
lines changed

2 files changed

+73
-6
lines changed

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

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
<?php
22
/**
3-
* Copyright 2025 Adobe
3+
* Copyright 2020 Adobe
44
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

88
namespace Magento\CustomerGraphQl\Model\Resolver;
99

10+
use Exception;
11+
use Magento\Customer\Model\EmailNotificationInterface;
1012
use Magento\CustomerGraphQl\Model\Customer\ExtractCustomerData;
1113
use Magento\CustomerGraphQl\Model\Customer\GetCustomer;
1214
use Magento\CustomerGraphQl\Model\Customer\UpdateCustomerAccount;
15+
use Magento\Framework\App\ObjectManager;
1316
use Magento\Framework\GraphQl\Config\Element\Field;
1417
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
18+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface as ResolverContext;
1519
use Magento\Framework\GraphQl\Query\Resolver\Value;
1620
use Magento\Framework\GraphQl\Query\ResolverInterface;
1721
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
@@ -37,31 +41,40 @@ class UpdateCustomerEmail implements ResolverInterface
3741
*/
3842
private $extractCustomerData;
3943

44+
/**
45+
* @var EmailNotificationInterface
46+
*/
47+
private $emailNotification;
48+
4049
/**
4150
* @param GetCustomer $getCustomer
4251
* @param UpdateCustomerAccount $updateCustomerAccount
4352
* @param ExtractCustomerData $extractCustomerData
53+
* @param EmailNotificationInterface|null $emailNotification
4454
*/
4555
public function __construct(
4656
GetCustomer $getCustomer,
4757
UpdateCustomerAccount $updateCustomerAccount,
48-
ExtractCustomerData $extractCustomerData
58+
ExtractCustomerData $extractCustomerData,
59+
?EmailNotificationInterface $emailNotification = null
4960
) {
5061
$this->getCustomer = $getCustomer;
5162
$this->updateCustomerAccount = $updateCustomerAccount;
5263
$this->extractCustomerData = $extractCustomerData;
64+
$this->emailNotification = $emailNotification
65+
?? ObjectManager::getInstance()->get(EmailNotificationInterface::class);
5366
}
5467

5568
/**
5669
* Resolve customer email update mutation
5770
*
58-
* @param \Magento\Framework\GraphQl\Config\Element\Field $field
59-
* @param \Magento\Framework\GraphQl\Query\Resolver\ContextInterface $context
71+
* @param Field $field
72+
* @param ResolverContext $context
6073
* @param ResolveInfo $info
6174
* @param array|null $value
6275
* @param array|null $args
6376
* @return array|Value
64-
* @throws \Exception
77+
* @throws Exception
6578
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
6679
*/
6780
public function resolve(
@@ -77,6 +90,7 @@ public function resolve(
7790
}
7891

7992
$customer = $this->getCustomer->execute($context);
93+
$customerOriginalEmail = $customer->getEmail();
8094
$customer->setData('ignore_validation_flag', true);
8195
$this->updateCustomerAccount->execute(
8296
$customer,
@@ -86,7 +100,11 @@ public function resolve(
86100
],
87101
$context->getExtensionAttributes()->getStore()
88102
);
89-
103+
$this->emailNotification->credentialsChanged(
104+
$customer,
105+
$customerOriginalEmail,
106+
false
107+
);
90108
return ['customer' => $this->extractCustomerData->execute($customer)];
91109
}
92110
}

dev/tests/api-functional/testsuite/Magento/GraphQl/CustomerGraphQl/Model/Resolver/CustomerTest.php

+49
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Customer\Model\Customer;
1414
use Magento\Customer\Test\Fixture\Customer as CustomerFixture;
1515
use Magento\CustomerGraphQl\Model\Resolver\Customer as CustomerResolver;
16+
use Magento\Framework\Serialize\SerializerInterface;
1617
use Magento\NewsletterGraphQl\Model\Resolver\IsSubscribed;
1718
use Magento\Framework\ObjectManagerInterface;
1819
use Magento\Framework\Registry;
@@ -25,6 +26,7 @@
2526
use Magento\Store\Test\Fixture\Store as StoreFixture;
2627
use Magento\Store\Test\Fixture\Website as WebsiteFixture;
2728
use Magento\TestFramework\Fixture\DataFixture;
29+
use Magento\TestFramework\Fixture\DbIsolation;
2830
use Magento\TestFramework\Helper\Bootstrap;
2931
use Magento\TestFramework\TestCase\GraphQl\ResolverCacheAbstract;
3032
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
@@ -61,6 +63,11 @@ class CustomerTest extends ResolverCacheAbstract
6163
*/
6264
private $registry;
6365

66+
/**
67+
* @var SerializerInterface
68+
*/
69+
private $json;
70+
6471
protected function setUp(): void
6572
{
6673
$this->objectManager = Bootstrap::getObjectManager();
@@ -76,6 +83,7 @@ protected function setUp(): void
7683
$this->websiteRepository = $this->objectManager->get(
7784
WebsiteRepositoryInterface::class
7885
);
86+
$this->json = $this->objectManager->get(SerializerInterface::class);
7987

8088
// first register secure area so we have permission to delete customer in tests
8189
$this->registry = $this->objectManager->get(Registry::class);
@@ -830,6 +838,47 @@ private function getCustomerQuery(): string
830838
QUERY;
831839
}
832840

841+
/**
842+
* Test that updated customer email is returned in the response
843+
*
844+
* @throws Exception
845+
*/
846+
#[
847+
DbIsolation(false),
848+
DataFixture(CustomerFixture::class, ['email' => '[email protected]'], as: 'customer'),
849+
]
850+
public function testChangeEmailSuccessfully(): void
851+
{
852+
$currentPassword = 'password';
853+
$updatedEmail = '[email protected]';
854+
$query
855+
= <<<QUERY
856+
mutation {
857+
updateCustomerEmail(
858+
email: "$updatedEmail",
859+
password: "$currentPassword"
860+
) {
861+
customer {
862+
email
863+
}
864+
}
865+
}
866+
QUERY;
867+
$customer = $this->customerRepository->get('[email protected]');
868+
$customerToken = $this->generateCustomerToken(
869+
$customer->getEmail(),
870+
'password'
871+
);
872+
$response = $this->graphQlMutation(
873+
$query,
874+
[],
875+
'',
876+
['Authorization' => 'Bearer ' . $customerToken]
877+
);
878+
879+
$this->assertEquals($updatedEmail, $response['updateCustomerEmail']['customer']['email']);
880+
}
881+
833882
/**
834883
* Generate customer token
835884
*

0 commit comments

Comments
 (0)