Skip to content

Commit 02d3267

Browse files
MAGETWO-99636: Newsletter subscribe and unsubscribe emails sent when User creates account from Invitation account
1 parent 15100ac commit 02d3267

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

app/code/Magento/Customer/Controller/Account/CreatePost.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Customer\Controller\Account;
77

8+
use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
89
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
910
use Magento\Customer\Model\Account\Redirect as AccountRedirect;
1011
use Magento\Customer\Api\Data\AddressInterface;
@@ -133,6 +134,11 @@ class CreatePost extends AbstractAccount implements CsrfAwareActionInterface, Ht
133134
*/
134135
private $formKeyValidator;
135136

137+
/**
138+
* @var CustomerRepository
139+
*/
140+
private $customerRepository;
141+
136142
/**
137143
* @param Context $context
138144
* @param Session $customerSession
@@ -153,6 +159,7 @@ class CreatePost extends AbstractAccount implements CsrfAwareActionInterface, Ht
153159
* @param DataObjectHelper $dataObjectHelper
154160
* @param AccountRedirect $accountRedirect
155161
* @param Validator $formKeyValidator
162+
* @param CustomerRepository $customerRepository
156163
*
157164
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
158165
*/
@@ -175,6 +182,7 @@ public function __construct(
175182
CustomerExtractor $customerExtractor,
176183
DataObjectHelper $dataObjectHelper,
177184
AccountRedirect $accountRedirect,
185+
CustomerRepository $customerRepository,
178186
Validator $formKeyValidator = null
179187
) {
180188
$this->session = $customerSession;
@@ -195,6 +203,7 @@ public function __construct(
195203
$this->dataObjectHelper = $dataObjectHelper;
196204
$this->accountRedirect = $accountRedirect;
197205
$this->formKeyValidator = $formKeyValidator ?: ObjectManager::getInstance()->get(Validator::class);
206+
$this->customerRepository = $customerRepository;
198207
parent::__construct($context);
199208
}
200209

@@ -348,7 +357,11 @@ public function execute()
348357
->createAccount($customer, $password, $redirectUrl);
349358

350359
if ($this->getRequest()->getParam('is_subscribed', false)) {
351-
$this->subscriberFactory->create()->subscribeCustomerById($customer->getId());
360+
$subscriber = $this->subscriberFactory->create()->subscribeCustomerById($customer->getId());
361+
$extensionAttributes = $customer->getExtensionAttributes();
362+
$extensionAttributes->setIsSubscribed($subscriber->isSubscribed($customer));
363+
$customer->setExtensionAttributes($extensionAttributes);
364+
$this->customerRepository->save($customer);
352365
}
353366

354367
$this->_eventManager->dispatch(

0 commit comments

Comments
 (0)