/** * Convert an AbstractAddress object to an address object compatible * with the address validation service. * * @param AbstractCustomerAddress * @return \EbayEnterprise\Address\Api\Data\AddressInterface */ public function convertAbstractAddressToDataAddress(AbstractCustomerAddress $address) { $data = ['street' => array_filter($address->getStreet(), [$this, 'filterEmptyStreets']), 'city' => $address->getCity(), 'region_code' => $address->getRegionCode(), 'region_id' => $address->getRegionId(), 'region_name' => $address->getRegion(), 'country_id' => $address->getCountryId(), 'postcode' => $address->getPostcode()]; return $this->addressFactory->create(['data' => $data]); }
/** * Make address Data Object out of an address model * * @param AbstractAddress $addressModel * @param int $defaultBillingId * @param int $defaultShippingId * @return Address */ public function createAddressFromModel(AbstractAddress $addressModel, $defaultBillingId, $defaultShippingId) { $addressId = $addressModel->getId(); $attributes = $this->_metadataService->getAllAddressAttributeMetadata(); $addressData = array(); foreach ($attributes as $attribute) { $code = $attribute->getAttributeCode(); if (!is_null($addressModel->getData($code))) { $addressData[$code] = $addressModel->getData($code); } } $isDefaultBilling = $addressModel->getData('is_default_billing') === null && intval($addressId) ? $addressId === $defaultBillingId : $addressModel->getData('is_default_billing'); $isDefaultShipping = $addressModel->getData('is_default_shipping') === null && intval($addressId) ? $addressId === $defaultShippingId : $addressModel->getData('is_default_shipping'); $this->_addressBuilder->populateWithArray(array_merge($addressData, array(Address::KEY_STREET => $addressModel->getStreet(), Address::KEY_DEFAULT_BILLING => $isDefaultBilling, Address::KEY_DEFAULT_SHIPPING => $isDefaultShipping, Address::KEY_REGION => array(Region::KEY_REGION => $addressModel->getRegion(), Region::KEY_REGION_ID => $addressModel->getRegionId(), Region::KEY_REGION_CODE => $addressModel->getRegionCode())))); if ($addressId) { $this->_addressBuilder->setId($addressId); } if ($addressModel->getCustomerId() || $addressModel->getParentId()) { $customerId = $addressModel->getCustomerId() ?: $addressModel->getParentId(); $this->_addressBuilder->setCustomerId($customerId); } $addressDataObject = $this->_addressBuilder->create(); return $addressDataObject; }
/** * Returns street * * @return string[] */ public function getStreet() { return parent::getStreet(); }