コード例 #1
0
 /**
  * Convert a Thelia address (Address or OrderAddress) to ImmutableAddressInterface
  *
  * @param \Thelia\Model\OrderAddress|OrderAddress $address
  * @return Address|\CommerceGuys\Addressing\Model\ImmutableAddressInterface
  */
 protected function mapTheliaAddress($address, $locale = null)
 {
     $country = $address->getCountry();
     if (null === $locale) {
         $locale = Lang::getDefaultLanguage()->getLocale();
     }
     $customerTitle = $address->getCustomerTitle()->setLocale($this->denormalizeLocale($locale))->getShort();
     $addressModel = new Address();
     $addressModel = $addressModel->withCountryCode($country->getIsoalpha2())->withAddressLine1($address->getAddress1())->withAddressLine2($address->getAddress2())->withPostalCode($address->getZipcode())->withLocality($address->getCity())->withOrganization($address->getCompany())->withRecipient(sprintf('%s %s %s', $customerTitle, $address->getLastname(), $address->getFirstname()));
     if ($country->getHasStates() && intval($address->getStateId()) !== 0) {
         $addressModel = $addressModel->withAdministrativeArea(sprintf('%s-%s', $country->getIsoalpha2(), $address->getState()->getIsocode()));
     }
     return $addressModel;
 }