7
7
8
8
use Magento \Customer \Api \AccountManagementInterface ;
9
9
use Magento \Customer \Api \AddressRepositoryInterface ;
10
+ use Magento \Customer \Api \CustomerMetadataInterface ;
10
11
use Magento \Customer \Api \CustomerRepositoryInterface ;
11
12
use Magento \Customer \Api \Data \AddressInterfaceFactory ;
12
13
use Magento \Customer \Api \Data \CustomerInterfaceFactory ;
@@ -145,6 +146,7 @@ protected function _validateCustomer($response)
145
146
);
146
147
$ customerForm ->setInvisibleIgnored (true );
147
148
149
+ $ this ->setCurrentCustomerStore ();
148
150
$ data = $ customerForm ->extractData ($ this ->getRequest (), 'customer ' );
149
151
150
152
if ($ customer ->getWebsiteId ()) {
@@ -161,11 +163,11 @@ protected function _validateCustomer($response)
161
163
$ entity_id = $ submittedData ['entity_id ' ];
162
164
$ customer ->setId ($ entity_id );
163
165
}
164
- if (isset ($ data ['website_id ' ]) && is_numeric ($ data ['website_id ' ])) {
165
- $ website = $ this ->storeManager ->getWebsite ($ data ['website_id ' ]);
166
- $ storeId = current ($ website ->getStoreIds ());
167
- $ this ->storeManager ->setCurrentStore ($ storeId );
168
- }
166
+ /* if (isset($data['website_id']) && is_numeric($data['website_id'])) {
167
+ $website = $this->storeManager->getWebsite($data['website_id']);
168
+ $storeId = current($website->getStoreIds());
169
+ $this->storeManager->setCurrentStore($storeId);
170
+ }*/
169
171
$ errors = $ this ->customerAccountManagement ->validate ($ customer )->getMessages ();
170
172
} catch (\Magento \Framework \Validator \Exception $ exception ) {
171
173
/* @var $error Error */
@@ -206,4 +208,22 @@ public function execute()
206
208
$ resultJson ->setData ($ response );
207
209
return $ resultJson ;
208
210
}
211
+
212
+ /**
213
+ * Set store ID for the current customer.
214
+ *
215
+ * @return void
216
+ */
217
+ private function setCurrentCustomerStore (): void
218
+ {
219
+ $ requestData = $ this ->getRequest ()->getParam (CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER );
220
+
221
+ $ storeId = $ requestData ['store_id ' ] ?? null ;
222
+ if (!$ storeId ) {
223
+ $ websiteId = $ requestData ['website_id ' ] ?? null ;
224
+ $ website = $ this ->storeManager ->getWebsite ($ websiteId );
225
+ $ storeId = current ($ website ->getStoreIds ());
226
+ }
227
+ $ this ->storeManager ->setCurrentStore ($ storeId );
228
+ }
209
229
}
0 commit comments