示例#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;
 }
示例#2
0
 /**
  * Get URL of page, at which customer billing address can be set.
  *
  * @param \Magento\Customer\Api\Data\AddressInterface $address
  * @return string
  */
 public function getSetAddressUrl(\Magento\Customer\Api\Data\AddressInterface $address)
 {
     return $this->getUrl('*/*/setBilling', ['id' => $address->getId()]);
 }
示例#3
0
 /**
  * Retrieve the Url for editing the specified address.
  *
  * @param \Magento\Customer\Api\Data\AddressInterface $address
  * @return string
  */
 public function getAddressEditUrl($address)
 {
     return $this->_urlBuilder->getUrl('customer/address/edit', ['_secure' => true, 'id' => $address->getId()]);
 }
 /**
  * This method is necessary because a customer address does not have a getData() method to retrieve all the address
  * fields.
  *
  * @param CustomerAddressInterface $customerAddress
  * @return array
  */
 protected function getCustomerAddressData(CustomerAddressInterface $customerAddress)
 {
     $customerAddressData = [CustomerAddressInterface::COUNTRY_ID => $customerAddress->getCountryId(), CustomerAddressInterface::STREET => $customerAddress->getStreet(), CustomerAddressInterface::POSTCODE => $customerAddress->getPostcode(), CustomerAddressInterface::CITY => $customerAddress->getCity(), CustomerAddressInterface::COMPANY => $customerAddress->getCompany(), CustomerAddressInterface::CUSTOM_ATTRIBUTES => $customerAddress->getCustomAttributes(), CustomerAddressInterface::CUSTOMER_ID => $customerAddress->getCustomerId(), CustomerAddressInterface::EXTENSION_ATTRIBUTES_KEY => $customerAddress->getExtensionAttributes(), CustomerAddressInterface::FAX => $customerAddress->getFax(), CustomerAddressInterface::FIRSTNAME => $customerAddress->getFirstname(), CustomerAddressInterface::ID => $customerAddress->getId(), CustomerAddressInterface::LASTNAME => $customerAddress->getLastname(), CustomerAddressInterface::MIDDLENAME => $customerAddress->getMiddlename(), CustomerAddressInterface::PREFIX => $customerAddress->getPrefix(), CustomerAddressInterface::REGION => $customerAddress->getRegion(), CustomerAddressInterface::REGION_ID => $customerAddress->getRegionId(), CustomerAddressInterface::STREET => $customerAddress->getStreet(), CustomerAddressInterface::SUFFIX => $customerAddress->getSuffix(), CustomerAddressInterface::TELEPHONE => $customerAddress->getTelephone(), CustomerAddressInterface::VAT_ID => $customerAddress->getVatId(), CustomerAddressInterface::DEFAULT_BILLING => $customerAddress->isDefaultBilling(), CustomerAddressInterface::DEFAULT_SHIPPING => $customerAddress->isDefaultShipping()];
     return $customerAddressData;
 }
 /**
  * Store the original customer address data.
  *
  * @param CustomerAddressInterface
  * @return self
  */
 public function setOriginalCustomerAddress(CustomerAddressInterface $address)
 {
     $region = $address->getRegion() ?: $this->customerRegionFactory->create();
     $addressData = ['id' => $address->getId(), 'customer_id' => $address->getCustomerId(), 'region' => ['region_id' => $region->getRegionId(), 'region_code' => $region->getRegionCode(), 'region' => $region->getRegion()], 'country_id' => $address->getCountryId(), 'street' => $address->getStreet(), 'company' => $address->getCompany(), 'telephone' => $address->getTelephone(), 'fax' => $address->getFax(), 'postcode' => $address->getPostcode(), 'city' => $address->getCity(), 'firstname' => $address->getFirstname(), 'lastname' => $address->getLastname(), 'middlename' => $address->getMiddlename(), 'prefix' => $address->getPrefix(), 'suffix' => $address->getSuffix(), 'vat_id' => $address->getVatId(), 'is_default_shipping' => $address->isDefaultShipping(), 'is_default_billing' => $address->isDefaultBilling()];
     $this->sessionManager->setOriginalCustomerAddressData($addressData);
 }
示例#6
0
 /**
  * Delete customer address.
  *
  * @param \Magento\Customer\Api\Data\AddressInterface $address
  * @return bool true on success
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function delete(\Magento\Customer\Api\Data\AddressInterface $address)
 {
     $addressId = $address->getId();
     $address = $this->addressRegistry->retrieve($addressId);
     $customerModel = $this->customerRegistry->retrieve($address->getCustomerId());
     $customerModel->getAddressesCollection()->clear();
     $this->addressResource->delete($address);
     $this->addressRegistry->remove($addressId);
     return true;
 }
 /**
  * @Then The address should not be saved
  */
 public function theAddressShouldNotBeSaved()
 {
     Assert::assertNull($this->customerAddress->getId(), 'Address was saved and assigned an id');
     Assert::assertNotNull($this->saveAddressException, 'Exception was not thrown while saving the address');
 }