Exemplo n.º 1
0
 /**
  * Prepare the layout of the address edit block.
  *
  * @return $this
  */
 protected function _prepareLayout()
 {
     parent::_prepareLayout();
     // Init address object
     if ($addressId = $this->getRequest()->getParam('id')) {
         try {
             $this->_address = $this->_addressRepository->getById($addressId);
             if ($this->_address->getCustomerId() != $this->_customerSession->getCustomerId()) {
                 $this->_address = null;
             }
         } catch (NoSuchEntityException $e) {
             $this->_address = null;
         }
     }
     if ($this->_address === null || !$this->_address->getId()) {
         $this->_address = $this->addressDataFactory->create();
         $customer = $this->getCustomer();
         $this->_address->setPrefix($customer->getPrefix());
         $this->_address->setFirstname($customer->getFirstname());
         $this->_address->setMiddlename($customer->getMiddlename());
         $this->_address->setLastname($customer->getLastname());
         $this->_address->setSuffix($customer->getSuffix());
     }
     $this->pageConfig->getTitle()->set($this->getTitle());
     if ($postedData = $this->_customerSession->getAddressFormData(true)) {
         if (!empty($postedData['region_id']) || !empty($postedData['region'])) {
             $postedData['region'] = ['region_id' => $postedData['region_id'], 'region' => $postedData['region']];
         }
         $this->dataObjectHelper->populateWithArray($this->_address, $postedData, '\\Magento\\Customer\\Api\\Data\\AddressInterface');
     }
     return $this;
 }