25 private $emailNotification;
35 if ($this->
getRequest()->getPost(
'customer')) {
36 $additionalAttributes = [
41 'extension_attributes',
46 CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER,
47 $additionalAttributes,
53 $customerData[
'disable_auto_group_change'] = (int) filter_var(
55 FILTER_VALIDATE_BOOLEAN
71 protected function _extractData(
74 $additionalAttributes = [],
77 $metadataForm = $this->getMetadataForm(
$entityType, $formCode, $scope);
78 $formData = $metadataForm->extractData($this->
getRequest(), $scope);
79 $formData = $metadataForm->compactData($formData);
83 $object = $this->_objectFactory->create([
'data' => $this->
getRequest()->getPostValue()]);
90 $formAttributes = $metadataForm->getAttributes();
94 if (
$attribute->getFrontendInput() !=
'boolean' 101 if (empty($formData[
'extension_attributes'])) {
102 unset($formData[
'extension_attributes']);
120 foreach ($addressIdList as $addressId) {
121 $scope = sprintf(
'address/%s', $addressId);
123 'adminhtml_customer_address',
124 AddressMetadataInterface::ENTITY_TYPE_ADDRESS,
125 [
'default_billing',
'default_shipping'],
129 if (is_numeric($addressId)) {
182 $returnToEdit =
false;
183 $originalRequestData = $this->
getRequest()->getPostValue();
187 if ($originalRequestData) {
194 $currentCustomer = $this->_customerRepository->getById(
$customerId);
196 $this->customerMapper->toFlatArray($currentCustomer),
203 $customer = $this->customerDataFactory->create();
204 $this->dataObjectHelper->populateWithArray(
207 \
Magento\Customer\Api\Data\CustomerInterface::class
215 'region_id' => $regionId,
217 $addressDataObject = $this->addressDataFactory->create();
218 $this->dataObjectHelper->populateWithArray(
221 \
Magento\Customer\Api\Data\AddressInterface::class
226 $this->_eventManager->dispatch(
227 'adminhtml_customer_prepare_save',
237 $this->_customerRepository->save(
$customer);
239 $this->getEmailNotification()->credentialsChanged(
$customer, $currentCustomer->getEmail());
245 $isSubscribed =
null;
246 if ($this->_authorization->isAllowed(
null)) {
247 $isSubscribed = $this->
getRequest()->getPost(
'subscription');
249 if ($isSubscribed !==
null) {
250 if ($isSubscribed !==
'0') {
251 $this->_subscriberFactory->create()->subscribeCustomerById(
$customerId);
253 $this->_subscriberFactory->create()->unsubscribeCustomerById(
$customerId);
258 $this->_eventManager->dispatch(
259 'adminhtml_customer_save_after',
265 $this->messageManager->addSuccess(
__(
'You saved the customer.'));
266 $returnToEdit = (bool)$this->
getRequest()->getParam(
'back',
false);
268 $messages = $exception->getMessages();
269 if (empty($messages)) {
270 $messages = $exception->getMessage();
273 $this->
_getSession()->setCustomerFormData($originalRequestData);
274 $returnToEdit =
true;
275 }
catch (\
Magento\Framework\Exception\AbstractAggregateException $exception) {
276 $errors = $exception->getErrors();
279 $messages[] = $error->getMessage();
282 $this->
_getSession()->setCustomerFormData($originalRequestData);
283 $returnToEdit =
true;
284 }
catch (LocalizedException $exception) {
286 $this->
_getSession()->setCustomerFormData($originalRequestData);
287 $returnToEdit =
true;
288 }
catch (\Exception $exception) {
289 $this->messageManager->addException($exception,
__(
'Something went wrong while saving the customer.'));
290 $this->
_getSession()->setCustomerFormData($originalRequestData);
291 $returnToEdit =
true;
294 $resultRedirect = $this->resultRedirectFactory->create();
297 $resultRedirect->setPath(
302 $resultRedirect->setPath(
308 $resultRedirect->setPath(
'customer/index');
310 return $resultRedirect;
319 private function getEmailNotification()
321 if (!($this->emailNotification instanceof EmailNotificationInterface)) {
322 return \Magento\Framework\App\ObjectManager::getInstance()->get(
323 EmailNotificationInterface::class
326 return $this->emailNotification;
338 private function getMetadataForm(
$entityType, $formCode, $scope)
342 if (
$entityType == CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER) {
350 if (
$entityType == AddressMetadataInterface::ENTITY_TYPE_ADDRESS) {
351 $scopeData = explode(
'/', $scope);
352 if (isset($scopeData[1]) && is_numeric($scopeData[1])) {
358 $metadataForm = $this->_formFactory->create(
363 Form::DONT_IGNORE_INVISIBLE
366 return $metadataForm;
374 private function getCurrentCustomerId()
376 $originalRequestData = $this->
getRequest()->getPostValue(CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER);
378 $customerId = isset($originalRequestData[
'entity_id'])
379 ? $originalRequestData[
'entity_id']
const CURRENT_CUSTOMER_ID
saveDefaultFlags(array $addressIdList, array & $extractedCustomerData)
_extractCustomerAddressData(array & $extractedCustomerData)
_addSessionErrorMessages($messages)