added cache to get default country and currency
This commit is contained in:
@@ -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)
|
||||
if (self::$defaultCountry == null) {
|
||||
throw new \LogicException(Translator::getInstance()->trans("Cannot find a default country. Please define one."));
|
||||
}
|
||||
}
|
||||
|
||||
return $dc;
|
||||
return self::$defaultCountry;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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) {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user