You are here

function commerce_currency_resolver_install in Commerce Currency Resolver 8

Implements hook_install().

File

./commerce_currency_resolver.install, line 14
Install file for commerce_currency_resolver.

Code

function commerce_currency_resolver_install() {

  // @see commerce_price_install().
  if (!\Drupal::isConfigSyncing()) {

    // Get default country and their currency.
    $default_country = \Drupal::config('system.date')
      ->get('country.default');
    $default_country = $default_country ?: 'US';
    $country_repository = new CountryRepository();
    $country = $country_repository
      ->get($default_country);
    $currency_code = $country
      ->getCurrencyCode();

    // Set initial default currency by default country.
    // User can change it later.
    \Drupal::service('config.factory')
      ->getEditable('commerce_currency_resolver.settings')
      ->set('currency_default', $currency_code)
      ->save();
  }
}