|
8 | 8 | namespace Magento\CustomerGraphQl\Model\Resolver;
|
9 | 9 |
|
10 | 10 | use Magento\Customer\Api\AccountManagementInterface;
|
| 11 | +use Magento\Customer\Model\EmailNotificationInterface; |
11 | 12 | use Magento\CustomerGraphQl\Model\Customer\CheckCustomerPassword;
|
12 | 13 | use Magento\CustomerGraphQl\Model\Customer\ExtractCustomerData;
|
13 | 14 | use Magento\CustomerGraphQl\Model\Customer\GetCustomer;
|
| 15 | +use Magento\Framework\App\ObjectManager; |
14 | 16 | use Magento\Framework\Exception\LocalizedException;
|
15 | 17 | use Magento\Framework\GraphQl\Config\Element\Field;
|
16 | 18 | use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
|
@@ -44,22 +46,31 @@ class ChangePassword implements ResolverInterface
|
44 | 46 | */
|
45 | 47 | private $extractCustomerData;
|
46 | 48 |
|
| 49 | + /** |
| 50 | + * @var EmailNotificationInterface |
| 51 | + */ |
| 52 | + private $emailNotification; |
| 53 | + |
47 | 54 | /**
|
48 | 55 | * @param GetCustomer $getCustomer
|
49 | 56 | * @param CheckCustomerPassword $checkCustomerPassword
|
50 | 57 | * @param AccountManagementInterface $accountManagement
|
51 | 58 | * @param ExtractCustomerData $extractCustomerData
|
| 59 | + * @param EmailNotificationInterface|null $emailNotification |
52 | 60 | */
|
53 | 61 | public function __construct(
|
54 | 62 | GetCustomer $getCustomer,
|
55 | 63 | CheckCustomerPassword $checkCustomerPassword,
|
56 | 64 | AccountManagementInterface $accountManagement,
|
57 |
| - ExtractCustomerData $extractCustomerData |
| 65 | + ExtractCustomerData $extractCustomerData, |
| 66 | + ?EmailNotificationInterface $emailNotification = null |
58 | 67 | ) {
|
59 | 68 | $this->getCustomer = $getCustomer;
|
60 | 69 | $this->checkCustomerPassword = $checkCustomerPassword;
|
61 | 70 | $this->accountManagement = $accountManagement;
|
62 | 71 | $this->extractCustomerData = $extractCustomerData;
|
| 72 | + $this->emailNotification = $emailNotification |
| 73 | + ?? ObjectManager::getInstance()->get(EmailNotificationInterface::class); |
63 | 74 | }
|
64 | 75 |
|
65 | 76 | /**
|
@@ -89,12 +100,25 @@ public function resolve(
|
89 | 100 | $this->checkCustomerPassword->execute($args['currentPassword'], $customerId);
|
90 | 101 |
|
91 | 102 | try {
|
92 |
| - $this->accountManagement->changePasswordById($customerId, $args['currentPassword'], $args['newPassword']); |
| 103 | + $isPasswordChanged = $this->accountManagement->changePasswordById( |
| 104 | + $customerId, |
| 105 | + $args['currentPassword'], |
| 106 | + $args['newPassword'] |
| 107 | + ); |
93 | 108 | } catch (LocalizedException $e) {
|
94 | 109 | throw new GraphQlInputException(__($e->getMessage()), $e);
|
95 | 110 | }
|
96 | 111 |
|
97 | 112 | $customer = $this->getCustomer->execute($context);
|
| 113 | + |
| 114 | + if ($isPasswordChanged) { |
| 115 | + $this->emailNotification->credentialsChanged( |
| 116 | + $customer, |
| 117 | + $customer->getEmail(), |
| 118 | + $isPasswordChanged |
| 119 | + ); |
| 120 | + } |
| 121 | + |
98 | 122 | return $this->extractCustomerData->execute($customer);
|
99 | 123 | }
|
100 | 124 | }
|
0 commit comments