/** * Get address format based on locale or region, if argument is not passed locale from * system configuration will be used. * * @param string|null $localeOrRegion * @throws \RuntimeException */ public function getAddressFormat($localeOrRegion = null) { if (!$localeOrRegion) { $localeOrRegion = $this->localeSettings->getLocale(); } $addressFormats = $this->localeSettings->getAddressFormats(); // matched by country (for example - "RU") if (isset($addressFormats[$localeOrRegion][LocaleSettings::ADDRESS_FORMAT_KEY])) { return $addressFormats[$localeOrRegion][LocaleSettings::ADDRESS_FORMAT_KEY]; } // matched by locale region - "CA" $localeParts = \Locale::parseLocale($localeOrRegion); if (isset($localeParts[\Locale::REGION_TAG])) { $match = $localeParts[\Locale::REGION_TAG]; if (isset($match, $addressFormats[$match][LocaleSettings::ADDRESS_FORMAT_KEY])) { return $addressFormats[$match][LocaleSettings::ADDRESS_FORMAT_KEY]; } } // match by default country in system configuration settings $match = $this->localeSettings->getCountry(); if ($match !== $localeOrRegion && isset($addressFormats[$match][LocaleSettings::ADDRESS_FORMAT_KEY])) { return $addressFormats[$match][LocaleSettings::ADDRESS_FORMAT_KEY]; } // fallback to default country $match = LocaleConfiguration::DEFAULT_COUNTRY; if (isset($addressFormats[$match][LocaleSettings::ADDRESS_FORMAT_KEY])) { return $addressFormats[$match][LocaleSettings::ADDRESS_FORMAT_KEY]; } throw new \RuntimeException(sprintf('Cannot get address format for "%s"', $localeOrRegion)); }
public function testGetCountryDefault() { $expectedCountry = 'US'; $this->configManager->expects($this->at(0))->method('get')->with('oro_locale.country')->will($this->returnValue(null)); $this->configManager->expects($this->at(1))->method('get')->with('oro_locale.locale')->will($this->returnValue('en_US')); $this->assertEquals($expectedCountry, $this->localeSettings->getCountry()); $this->assertEquals($expectedCountry, $this->localeSettings->getCountry()); }