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 ;
@@ -133,6 +134,11 @@ class CreatePost extends AbstractAccount implements CsrfAwareActionInterface, Ht
133
134
*/
134
135
private $ formKeyValidator ;
135
136
137
+ /**
138
+ * @var CustomerRepository
139
+ */
140
+ private $ customerRepository ;
141
+
136
142
/**
137
143
* @param Context $context
138
144
* @param Session $customerSession
@@ -153,6 +159,7 @@ class CreatePost extends AbstractAccount implements CsrfAwareActionInterface, Ht
153
159
* @param DataObjectHelper $dataObjectHelper
154
160
* @param AccountRedirect $accountRedirect
155
161
* @param Validator $formKeyValidator
162
+ * @param CustomerRepository $customerRepository
156
163
*
157
164
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
158
165
*/
@@ -175,6 +182,7 @@ public function __construct(
175
182
CustomerExtractor $ customerExtractor ,
176
183
DataObjectHelper $ dataObjectHelper ,
177
184
AccountRedirect $ accountRedirect ,
185
+ CustomerRepository $ customerRepository ,
178
186
Validator $ formKeyValidator = null
179
187
) {
180
188
$ this ->session = $ customerSession ;
@@ -195,6 +203,7 @@ public function __construct(
195
203
$ this ->dataObjectHelper = $ dataObjectHelper ;
196
204
$ this ->accountRedirect = $ accountRedirect ;
197
205
$ this ->formKeyValidator = $ formKeyValidator ?: ObjectManager::getInstance ()->get (Validator::class);
206
+ $ this ->customerRepository = $ customerRepository ;
198
207
parent ::__construct ($ context );
199
208
}
200
209
@@ -348,7 +357,11 @@ public function execute()
348
357
->createAccount ($ customer , $ password , $ redirectUrl );
349
358
350
359
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 );
352
365
}
353
366
354
367
$ this ->_eventManager ->dispatch (
0 commit comments