4
4
* See COPYING.txt for license details.
5
5
*/
6
6
7
- // @codingStandardsIgnoreFile
8
-
9
7
/**
10
8
* Backend Directory currency backend model
11
9
* Allows dispatching before and after events for each controller action
14
12
15
13
class Base extends AbstractCurrency
16
14
{
15
+ /** @var \Magento\Directory\Model\CurrencyFactory */
16
+ private $ currencyFactory ;
17
+
18
+ /**
19
+ * @param \Magento\Framework\Model\Context $context
20
+ * @param \Magento\Framework\Registry $registry
21
+ * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
22
+ * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
23
+ * @param \Magento\Directory\Model\CurrencyFactory $currencyFactory
24
+ * @param \Magento\Framework\Model\Resource\AbstractResource $resource
25
+ * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
26
+ * @param array $data
27
+ */
28
+ public function __construct (
29
+ \Magento \Framework \Model \Context $ context ,
30
+ \Magento \Framework \Registry $ registry ,
31
+ \Magento \Framework \App \Config \ScopeConfigInterface $ config ,
32
+ \Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ,
33
+ \Magento \Directory \Model \CurrencyFactory $ currencyFactory ,
34
+ \Magento \Framework \Model \Resource \AbstractResource $ resource = null ,
35
+ \Magento \Framework \Data \Collection \AbstractDb $ resourceCollection = null ,
36
+ array $ data = []
37
+ ) {
38
+ parent ::__construct ($ context , $ registry , $ config , $ scopeConfig , $ resource , $ resourceCollection , $ data );
39
+ $ this ->currencyFactory = $ currencyFactory ;
40
+ }
41
+
17
42
/**
18
43
* Check base currency is available in installed currencies
19
44
*
@@ -22,9 +47,14 @@ class Base extends AbstractCurrency
22
47
*/
23
48
public function afterSave ()
24
49
{
25
- if (!in_array ($ this ->getValue (), $ this ->_getInstalledCurrencies ())) {
26
- throw new \Magento \Framework \Exception \LocalizedException (__ ('Sorry, we haven \'t installed the base currency you selected. ' ));
50
+ $ value = $ this ->getValue ();
51
+ if (!in_array ($ value , $ this ->_getInstalledCurrencies ())) {
52
+ throw new \Magento \Framework \Exception \LocalizedException (
53
+ __ ('Sorry, we haven \'t installed the base currency you selected. ' )
54
+ );
27
55
}
56
+
57
+ $ this ->currencyFactory ->create ()->saveRates ([$ value =>[$ value => 1 ]]);
28
58
return $ this ;
29
59
}
30
60
}
0 commit comments