Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Edit.php
Go to the documentation of this file.
1 <?php
7 
8 use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
11 
13 {
22  public function execute()
23  {
25 
26  $customerData = [];
27  $customerData['account'] = [];
28  $customerData['address'] = [];
29  $customer = null;
30  $isExistingCustomer = (bool)$customerId;
31  if ($isExistingCustomer) {
32  try {
33  $customer = $this->_customerRepository->getById($customerId);
34  $customerData['account'] = $this->customerMapper->toFlatArray($customer);
36  try {
37  $addresses = $customer->getAddresses();
38  foreach ($addresses as $address) {
39  $customerData['address'][$address->getId()] = $this->addressMapper->toFlatArray($address);
40  $customerData['address'][$address->getId()]['id'] = $address->getId();
41  }
42  } catch (NoSuchEntityException $e) {
43  //do nothing
44  }
45  } catch (NoSuchEntityException $e) {
46  $this->messageManager->addException($e, __('Something went wrong while editing the customer.'));
47  $resultRedirect = $this->resultRedirectFactory->create();
48  $resultRedirect->setPath('customer/*/index');
49  return $resultRedirect;
50  }
51  }
52  $customerData['customer_id'] = $customerId;
53  $this->_getSession()->setCustomerData($customerData);
54 
55  $resultPage = $this->resultPageFactory->create();
56  $resultPage->setActiveMenu('Magento_Customer::customer_manage');
57  $this->prepareDefaultCustomerTitle($resultPage);
58  $resultPage->setActiveMenu('Magento_Customer::customer');
59  if ($isExistingCustomer) {
60  $resultPage->getConfig()->getTitle()->prepend($this->_viewHelper->getCustomerName($customer));
61  } else {
62  $resultPage->getConfig()->getTitle()->prepend(__('New Customer'));
63  }
64  return $resultPage;
65  }
66 }
$customerData
$customer
Definition: customers.php:11
$addresses
Definition: address_list.php:7
__()
Definition: __.php:13
$address
Definition: customer.php:38
prepareDefaultCustomerTitle(\Magento\Backend\Model\View\Result\Page $resultPage)
Definition: Index.php:276