Commit 245345b4 authored by bojanz's avatar bojanz

Issue #2910188 by bojanz: Import an initial currency when commerce_price is installed

parent f009693c
......@@ -21,3 +21,15 @@ function commerce_price_requirements($phase) {
return $requirements;
}
/**
* Implements hook_install().
*/
function commerce_price_install() {
// Import a currency to speed up initial store setup.
// If no default country is set, import the US Dollar, since it's common.
$default_country = \Drupal::config('system.date')->get('country.default');
$default_country = $default_country ?: 'US';
$currency_importer = \Drupal::service('commerce_price.currency_importer');
$currency_importer->importByCountry($default_country);
}
......@@ -13,6 +13,15 @@ use Drupal\Core\Url;
*/
class CurrencyTest extends CommerceBrowserTestBase {
/**
* Tests the initial currency creation.
*/
public function testInitialCurrency() {
// We are expecting commerce_price_install() to import 'USD'.
$currency = Currency::load('USD');
$this->assertNotEmpty($currency);
}
/**
* Tests importing a currency.
*/
......
......@@ -61,9 +61,6 @@ abstract class CommerceBrowserTestBase extends BrowserTestBase {
$this->adminUser = $this->drupalCreateUser($this->getAdministratorPermissions());
$this->drupalLogin($this->adminUser);
$currency_importer = \Drupal::service('commerce_price.currency_importer');
$currency_importer->import('USD');
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment