4
4
* See COPYING.txt for license details.
5
5
*/
6
6
7
- /**
8
- * Locale currency source
9
- */
10
7
namespace Magento \Config \Model \Config \Source \Locale ;
11
8
9
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
10
+ use Magento \Framework \App \ObjectManager ;
11
+ use Magento \Framework \Locale \ListsInterface ;
12
+
12
13
/**
14
+ * Locale currency source.
15
+ *
13
16
* @api
14
17
* @since 100.0.2
15
18
*/
@@ -21,27 +24,70 @@ class Currency implements \Magento\Framework\Option\ArrayInterface
21
24
protected $ _options ;
22
25
23
26
/**
24
- * @var \Magento\Framework\Locale\ ListsInterface
27
+ * @var ListsInterface
25
28
*/
26
29
protected $ _localeLists ;
27
30
28
31
/**
29
- * @param \Magento\Framework\Locale\ListsInterface $localeLists
32
+ * @var ScopeConfigInterface
30
33
*/
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
+ ) {
33
49
$ this ->_localeLists = $ localeLists ;
50
+ $ this ->config = $ config ?: ObjectManager::getInstance ()->get (ScopeConfigInterface::class);
34
51
}
35
52
36
53
/**
37
- * @return array
54
+ * @inheritdoc
38
55
*/
39
56
public function toOptionArray ()
40
57
{
41
58
if (!$ this ->_options ) {
42
59
$ this ->_options = $ this ->_localeLists ->getOptionCurrencies ();
43
60
}
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
+
45
71
return $ options ;
46
72
}
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
+ }
47
93
}
0 commit comments