diff --git a/core/lib/Thelia/Model/Country.php b/core/lib/Thelia/Model/Country.php index 038bd5a61..9d94c6824 100644 --- a/core/lib/Thelia/Model/Country.php +++ b/core/lib/Thelia/Model/Country.php @@ -16,6 +16,8 @@ class Country extends BaseCountry { use \Thelia\Model\Tools\ModelEventDispatcherTrait; + protected static $defaultCountry = null; + /** * * Put the current country as the default one. @@ -93,16 +95,19 @@ class Country extends BaseCountry /** * Return the default country * - * @throws LogicException if no default country is defined + * @throws \LogicException if no default country is defined */ public static function getDefaultCountry() { - $dc = CountryQuery::create()->findOneByByDefault(true); + if (null === self::$defaultCountry) { + self::$defaultCountry = CountryQuery::create()->findOneByByDefault(true); - if ($dc == null) - throw new \LogicException(Translator::getInstance()->trans("Cannot find a default country. Please define one.")); + if (self::$defaultCountry == null) { + throw new \LogicException(Translator::getInstance()->trans("Cannot find a default country. Please define one.")); + } + } - return $dc; + return self::$defaultCountry; } /** diff --git a/core/lib/Thelia/Model/Currency.php b/core/lib/Thelia/Model/Currency.php index 706553430..6a19088f7 100644 --- a/core/lib/Thelia/Model/Currency.php +++ b/core/lib/Thelia/Model/Currency.php @@ -14,15 +14,20 @@ class Currency extends BaseCurrency use \Thelia\Model\Tools\PositionManagementTrait; + protected static $defaultCurrency = null; + public static function getDefaultCurrency() { - $currency = CurrencyQuery::create()->findOneByByDefault(1); + if (null === self::$defaultCurrency) { - if (null === $currency) { - throw new \RuntimeException("No default currency is defined. Please define one."); + self::$defaultCurrency = CurrencyQuery::create()->findOneByByDefault(1); + + if (self::$defaultCurrency == null) { + throw new \RuntimeException("No default currency is defined. Please define one."); + } } - return $currency; + return self::$defaultCurrency; } /**