Skip to content

Commit bd1ae18

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-99636' into 2.3-develop-pr23
2 parents 2cbb45d + bfa47bb commit bd1ae18

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

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

Lines changed: 15 additions & 9 deletions
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;
@@ -38,6 +39,8 @@
3839
use Magento\Customer\Controller\AbstractAccount;
3940

4041
/**
42+
* Post create customer action
43+
*
4144
* @SuppressWarnings(PHPMD.TooManyFields)
4245
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
4346
*/
@@ -133,6 +136,11 @@ class CreatePost extends AbstractAccount implements CsrfAwareActionInterface, Ht
133136
*/
134137
private $formKeyValidator;
135138

139+
/**
140+
* @var CustomerRepository
141+
*/
142+
private $customerRepository;
143+
136144
/**
137145
* @param Context $context
138146
* @param Session $customerSession
@@ -152,6 +160,7 @@ class CreatePost extends AbstractAccount implements CsrfAwareActionInterface, Ht
152160
* @param CustomerExtractor $customerExtractor
153161
* @param DataObjectHelper $dataObjectHelper
154162
* @param AccountRedirect $accountRedirect
163+
* @param CustomerRepository $customerRepository
155164
* @param Validator $formKeyValidator
156165
*
157166
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -175,6 +184,7 @@ public function __construct(
175184
CustomerExtractor $customerExtractor,
176185
DataObjectHelper $dataObjectHelper,
177186
AccountRedirect $accountRedirect,
187+
CustomerRepository $customerRepository,
178188
Validator $formKeyValidator = null
179189
) {
180190
$this->session = $customerSession;
@@ -195,6 +205,7 @@ public function __construct(
195205
$this->dataObjectHelper = $dataObjectHelper;
196206
$this->accountRedirect = $accountRedirect;
197207
$this->formKeyValidator = $formKeyValidator ?: ObjectManager::getInstance()->get(Validator::class);
208+
$this->customerRepository = $customerRepository;
198209
parent::__construct($context);
199210
}
200211

@@ -328,34 +339,29 @@ public function execute()
328339
return $this->resultRedirectFactory->create()
329340
->setUrl($this->_redirect->error($url));
330341
}
331-
332342
$this->session->regenerateId();
333-
334343
try {
335344
$address = $this->extractAddress();
336345
$addresses = $address === null ? [] : [$address];
337-
338346
$customer = $this->customerExtractor->extract('customer_account_create', $this->_request);
339347
$customer->setAddresses($addresses);
340-
341348
$password = $this->getRequest()->getParam('password');
342349
$confirmation = $this->getRequest()->getParam('password_confirmation');
343350
$redirectUrl = $this->session->getBeforeAuthUrl();
344-
345351
$this->checkPasswordConfirmation($password, $confirmation);
346-
347352
$customer = $this->accountManagement
348353
->createAccount($customer, $password, $redirectUrl);
349354

350355
if ($this->getRequest()->getParam('is_subscribed', false)) {
351-
$this->subscriberFactory->create()->subscribeCustomerById($customer->getId());
356+
$extensionAttributes = $customer->getExtensionAttributes();
357+
$extensionAttributes->setIsSubscribed(true);
358+
$customer->setExtensionAttributes($extensionAttributes);
359+
$this->customerRepository->save($customer);
352360
}
353-
354361
$this->_eventManager->dispatch(
355362
'customer_register_success',
356363
['account_controller' => $this, 'customer' => $customer]
357364
);
358-
359365
$confirmationStatus = $this->accountManagement->getConfirmationStatus($customer->getId());
360366
if ($confirmationStatus === AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED) {
361367
$email = $this->customerUrl->getEmailConfirmationUrl($customer->getEmail());

0 commit comments

Comments
 (0)