Unverified Commit b37502d4 authored by Pablo Borowicz's avatar Pablo Borowicz Committed by GitHub
Browse files

Merge pull request #15173 from jolelievre/multi-shop-currency

CLDR has access to all currencies regardless of the current shop
parents 3928634d 60b096b7
......@@ -189,9 +189,9 @@ class CurrencyCore extends ObjectModel
}
if (is_array($this->name)) {
$this->name = ucfirst($this->name[$idLang]);
$this->name = Tools::ucfirst($this->name[$idLang]);
} else {
$this->name = ucfirst($this->name);
$this->name = Tools::ucfirst($this->name);
}
$this->iso_code_num = $this->numeric_iso_code;
......@@ -358,6 +358,27 @@ class CurrencyCore extends ObjectModel
return (bool) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
}
/**
* Returns the name of the currency (using the translated name base on the id_lang
* provided on creation). This method is useful when $this->name contains an array
* but you still need to get its name as a string.
*
* @return string
*/
public function getName()
{
if (is_string($this->name)) {
return $this->name;
}
$id_lang = $this->id_lang;
if ($id_lang === null) {
$id_lang = Configuration::get('PS_LANG_DEFAULT');
}
return Tools::ucfirst($this->name[$id_lang]);
}
/**
* Return available currencies.
*
......@@ -378,14 +399,20 @@ class CurrencyCore extends ObjectModel
/**
* Retrieve all currencies data from the database.
*
* @param bool $active If true only active are returned
* @param bool $groupBy Group by id_currency
* @param bool $currentShopOnly If true returns only currencies associated to current shop
*
* @return array Currency data from database
*
* @throws PrestaShopDatabaseException
*/
public static function findAll($active = true, $groupBy = false)
public static function findAll($active = true, $groupBy = false, $currentShopOnly = true)
{
$currencies = Db::getInstance()->executeS('
SELECT *
FROM `' . _DB_PREFIX_ . 'currency` c
' . Shop::addSqlAssociation('currency', 'c') . '
' . ($currentShopOnly ? Shop::addSqlAssociation('currency', 'c') : '') . '
WHERE `deleted` = 0' .
($active ? ' AND c.`active` = 1' : '') .
($groupBy ? ' GROUP BY c.`id_currency`' : '') .
......
......@@ -226,7 +226,7 @@ final class EditCurrencyHandler extends AbstractCurrencyHandler implements EditC
if (!in_array($shopId, $shopIds)) {
$shop = new Shop($shopId);
throw new DefaultCurrencyInMultiShopException(
$currency->name,
$currency->getName(),
$shop->name,
sprintf(
'Currency with id %s cannot be unassigned from shop with id %s because its the default currency.',
......@@ -240,7 +240,7 @@ final class EditCurrencyHandler extends AbstractCurrencyHandler implements EditC
if (!$currency->active) {
$shop = new Shop($shopId);
throw new DefaultCurrencyInMultiShopException(
$currency->name,
$currency->getName(),
$shop->name,
sprintf(
'Currency with id %s cannot be disabled from shop with id %s because its the default currency.',
......
......@@ -70,9 +70,9 @@ class CurrencyDataProvider implements CurrencyDataProviderInterface
/**
* {@inheritdoc}
*/
public function findAll()
public function findAll($currentShopOnly = true)
{
return Currency::findAll(false);
return Currency::findAll(false, false, $currentShopOnly);
}
/**
......
......@@ -47,11 +47,13 @@ interface CurrencyDataProviderInterface
public function getCurrencies($object = false, $active = true, $group_by = false);
/**
* Return raw currencies data from the database reated to the current shop.
* Return raw currencies data from the database.
*
* @return array Installed currencies
* @param bool $currentShopOnly If true returns only currencies associated to current shop
*
* @return array[] Installed currencies
*/
public function findAll();
public function findAll($currentShopOnly = true);
/**
* Get a Currency entity instance by ISO code.
......
......@@ -76,7 +76,7 @@ class CurrencyInstalled
*/
public function getAvailableCurrencyCodes()
{
$currencies = $this->dataProvider->findAll();
$currencies = $this->dataProvider->findAll(false);
$currencyIds = array_column($currencies, 'iso_code');
return $currencyIds;
......
Supports Markdown
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