You are here

public function CurrencyImporter::importByCountry in Price 3.x

Same name and namespace in other branches
  1. 8 src/CurrencyImporter.php \Drupal\price\CurrencyImporter::importByCountry()
  2. 2.0.x src/CurrencyImporter.php \Drupal\price\CurrencyImporter::importByCountry()
  3. 2.x src/CurrencyImporter.php \Drupal\price\CurrencyImporter::importByCountry()
  4. 3.0.x src/CurrencyImporter.php \Drupal\price\CurrencyImporter::importByCountry()

Imports currency data for the given country code.

Parameters

string $country_code: The country code.

Return value

\Drupal\price\Entity\CurrencyInterface|null The saved currency entity or NULL if the given country's currency isn't known.

Throws

\CommerceGuys\Intl\Exception\UnknownCountryException Thrown when the country couldn't be found in the library definitions.

Overrides CurrencyImporterInterface::importByCountry

File

src/CurrencyImporter.php, line 108

Class

CurrencyImporter
Default implementation of the currency importer.

Namespace

Drupal\price

Code

public function importByCountry($country_code) {
  $country_repository = new CountryRepository();
  $country = $country_repository
    ->get($country_code);
  $currency_code = $country
    ->getCurrencyCode();
  $entity = NULL;
  if ($currency_code) {
    $entity = $this
      ->import($currency_code);
  }
  return $entity;
}