Skip to content

Commit 37fa7b8

Browse files
committed
ACP2E-2791: Not able to Save Customer attribute information in Admin Edit customer section;
1 parent 3428ebc commit 37fa7b8

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ public function execute()
335335

336336
if ($this->getRequest()->getPostValue()) {
337337
try {
338+
$this->setCurrentCustomerStore();
339+
338340
// optional fields might be set in request for future processing by observers in other modules
339341
$customerData = $this->_extractCustomerData();
340342

@@ -551,6 +553,24 @@ private function getCurrentCustomerId()
551553
return $customerId;
552554
}
553555

556+
/**
557+
* Set store ID for the current customer.
558+
*
559+
* @return void
560+
*/
561+
private function setCurrentCustomerStore(): void
562+
{
563+
$originalRequestData = $this->getRequest()->getPostValue(CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER);
564+
565+
$storeId = $originalRequestData['store_id'] ?? null;
566+
if (!$storeId) {
567+
$websiteId = $originalRequestData['website_id'] ?? null;
568+
$website = $this->storeManager->getWebsite($websiteId);
569+
$storeId = current($website->getStoreIds());
570+
}
571+
$this->storeManager->setCurrentStore($storeId);
572+
}
573+
554574
/**
555575
* Disable Customer Address Validation
556576
*

app/code/Magento/Customer/Controller/Adminhtml/Index/Validate.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Customer\Api\AccountManagementInterface;
99
use Magento\Customer\Api\AddressRepositoryInterface;
10+
use Magento\Customer\Api\CustomerMetadataInterface;
1011
use Magento\Customer\Api\CustomerRepositoryInterface;
1112
use Magento\Customer\Api\Data\AddressInterfaceFactory;
1213
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
@@ -145,6 +146,7 @@ protected function _validateCustomer($response)
145146
);
146147
$customerForm->setInvisibleIgnored(true);
147148

149+
$this->setCurrentCustomerStore();
148150
$data = $customerForm->extractData($this->getRequest(), 'customer');
149151

150152
if ($customer->getWebsiteId()) {
@@ -161,11 +163,11 @@ protected function _validateCustomer($response)
161163
$entity_id = $submittedData['entity_id'];
162164
$customer->setId($entity_id);
163165
}
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+
}*/
169171
$errors = $this->customerAccountManagement->validate($customer)->getMessages();
170172
} catch (\Magento\Framework\Validator\Exception $exception) {
171173
/* @var $error Error */
@@ -206,4 +208,22 @@ public function execute()
206208
$resultJson->setData($response);
207209
return $resultJson;
208210
}
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+
}
209229
}

0 commit comments

Comments
 (0)