Skip to content

Commit 21b2d01

Browse files
ENGCOM-4857: [Backport] Shortening currency list in Configuration->General (replace PR #20397) #22551
- Merge Pull Request #22551 from amol2jcommerce/magento2:2.2-develop-PR-port-22230 - Merged commits: 1. f54c202
2 parents 1e230b1 + f54c202 commit 21b2d01

File tree

1 file changed

+55
-9
lines changed
  • app/code/Magento/Config/Model/Config/Source/Locale

1 file changed

+55
-9
lines changed

app/code/Magento/Config/Model/Config/Source/Locale/Currency.php

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
/**
8-
* Locale currency source
9-
*/
107
namespace Magento\Config\Model\Config\Source\Locale;
118

9+
use Magento\Framework\App\Config\ScopeConfigInterface;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Locale\ListsInterface;
12+
1213
/**
14+
* Locale currency source.
15+
*
1316
* @api
1417
* @since 100.0.2
1518
*/
@@ -21,27 +24,70 @@ class Currency implements \Magento\Framework\Option\ArrayInterface
2124
protected $_options;
2225

2326
/**
24-
* @var \Magento\Framework\Locale\ListsInterface
27+
* @var ListsInterface
2528
*/
2629
protected $_localeLists;
2730

2831
/**
29-
* @param \Magento\Framework\Locale\ListsInterface $localeLists
32+
* @var ScopeConfigInterface
3033
*/
31-
public function __construct(\Magento\Framework\Locale\ListsInterface $localeLists)
32-
{
34+
private $config;
35+
36+
/**
37+
* @var array
38+
*/
39+
private $installedCurrencies;
40+
41+
/**
42+
* @param ListsInterface $localeLists
43+
* @param ScopeConfigInterface $config
44+
*/
45+
public function __construct(
46+
ListsInterface $localeLists,
47+
ScopeConfigInterface $config = null
48+
) {
3349
$this->_localeLists = $localeLists;
50+
$this->config = $config ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class);
3451
}
3552

3653
/**
37-
* @return array
54+
* @inheritdoc
3855
*/
3956
public function toOptionArray()
4057
{
4158
if (!$this->_options) {
4259
$this->_options = $this->_localeLists->getOptionCurrencies();
4360
}
44-
$options = $this->_options;
61+
62+
$selected = array_flip($this->getInstalledCurrencies());
63+
64+
$options = array_filter(
65+
$this->_options,
66+
function ($option) use ($selected) {
67+
return isset($selected[$option['value']]);
68+
}
69+
);
70+
4571
return $options;
4672
}
73+
74+
/**
75+
* Retrieve Installed Currencies.
76+
*
77+
* @return array
78+
*/
79+
private function getInstalledCurrencies()
80+
{
81+
if (!$this->installedCurrencies) {
82+
$this->installedCurrencies = explode(
83+
',',
84+
$this->config->getValue(
85+
'system/currency/installed',
86+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
87+
)
88+
);
89+
}
90+
91+
return $this->installedCurrencies;
92+
}
4793
}

0 commit comments

Comments
 (0)