5
5
*/
6
6
namespace Magento \Customer \Controller \Account ;
7
7
8
+ use Magento \Customer \Api \CustomerRepositoryInterface as CustomerRepository ;
8
9
use Magento \Framework \App \Action \HttpPostActionInterface as HttpPostActionInterface ;
9
10
use Magento \Customer \Model \Account \Redirect as AccountRedirect ;
10
11
use Magento \Customer \Api \Data \AddressInterface ;
38
39
use Magento \Customer \Controller \AbstractAccount ;
39
40
40
41
/**
42
+ * Post create customer action
43
+ *
41
44
* @SuppressWarnings(PHPMD.TooManyFields)
42
45
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
43
46
*/
@@ -133,6 +136,11 @@ class CreatePost extends AbstractAccount implements CsrfAwareActionInterface, Ht
133
136
*/
134
137
private $ formKeyValidator ;
135
138
139
+ /**
140
+ * @var CustomerRepository
141
+ */
142
+ private $ customerRepository ;
143
+
136
144
/**
137
145
* @param Context $context
138
146
* @param Session $customerSession
@@ -152,6 +160,7 @@ class CreatePost extends AbstractAccount implements CsrfAwareActionInterface, Ht
152
160
* @param CustomerExtractor $customerExtractor
153
161
* @param DataObjectHelper $dataObjectHelper
154
162
* @param AccountRedirect $accountRedirect
163
+ * @param CustomerRepository $customerRepository
155
164
* @param Validator $formKeyValidator
156
165
*
157
166
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -175,6 +184,7 @@ public function __construct(
175
184
CustomerExtractor $ customerExtractor ,
176
185
DataObjectHelper $ dataObjectHelper ,
177
186
AccountRedirect $ accountRedirect ,
187
+ CustomerRepository $ customerRepository ,
178
188
Validator $ formKeyValidator = null
179
189
) {
180
190
$ this ->session = $ customerSession ;
@@ -195,6 +205,7 @@ public function __construct(
195
205
$ this ->dataObjectHelper = $ dataObjectHelper ;
196
206
$ this ->accountRedirect = $ accountRedirect ;
197
207
$ this ->formKeyValidator = $ formKeyValidator ?: ObjectManager::getInstance ()->get (Validator::class);
208
+ $ this ->customerRepository = $ customerRepository ;
198
209
parent ::__construct ($ context );
199
210
}
200
211
@@ -328,34 +339,29 @@ public function execute()
328
339
return $ this ->resultRedirectFactory ->create ()
329
340
->setUrl ($ this ->_redirect ->error ($ url ));
330
341
}
331
-
332
342
$ this ->session ->regenerateId ();
333
-
334
343
try {
335
344
$ address = $ this ->extractAddress ();
336
345
$ addresses = $ address === null ? [] : [$ address ];
337
-
338
346
$ customer = $ this ->customerExtractor ->extract ('customer_account_create ' , $ this ->_request );
339
347
$ customer ->setAddresses ($ addresses );
340
-
341
348
$ password = $ this ->getRequest ()->getParam ('password ' );
342
349
$ confirmation = $ this ->getRequest ()->getParam ('password_confirmation ' );
343
350
$ redirectUrl = $ this ->session ->getBeforeAuthUrl ();
344
-
345
351
$ this ->checkPasswordConfirmation ($ password , $ confirmation );
346
-
347
352
$ customer = $ this ->accountManagement
348
353
->createAccount ($ customer , $ password , $ redirectUrl );
349
354
350
355
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 );
352
360
}
353
-
354
361
$ this ->_eventManager ->dispatch (
355
362
'customer_register_success ' ,
356
363
['account_controller ' => $ this , 'customer ' => $ customer ]
357
364
);
358
-
359
365
$ confirmationStatus = $ this ->accountManagement ->getConfirmationStatus ($ customer ->getId ());
360
366
if ($ confirmationStatus === AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED ) {
361
367
$ email = $ this ->customerUrl ->getEmailConfirmationUrl ($ customer ->getEmail ());
0 commit comments