/** * Convert a customer address object to an address object compatible * with the address validation service. * * @param CustomerAddressInterface * @return \EbayEnterprise\Address\Api\Data\AddressInterface */ public function convertCustomerAddressToDataAddress(CustomerAddressInterface $address) { // When the region object on the customer address already has a region // code, it isn't necessary to load the direction region model to get the code. $customerRegion = $address->getRegion(); $region = $this->regionHelper->loadRegion($customerRegion->getRegionId(), $customerRegion->getRegionCode(), $customerRegion->getRegion(), $address->getCountryId()); $data = ['street' => array_filter($address->getStreet(), [$this, 'filterEmptyStreets']), 'city' => $address->getCity(), 'region_code' => $region->getCode(), 'region_id' => $region->getId(), 'region_name' => $region->getName(), 'country_id' => $address->getCountryId(), 'postcode' => $address->getPostcode()]; return $this->addressFactory->create(['data' => $data]); }
/** * 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); }
/** * Format the address object to match an expected format. * * @param AddressInterface * @return string */ protected function formatAddressData(AddressInterface $address) { return implode(' ', $address->getStreet()) . ' ' . $address->getCity() . ', ' . $address->getRegion()->getRegion() . ', ' . $address->getPostcode() . ' ' . $this->getCountryName($address->getCountryId()); }