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
{
17
- /** @var \Magento\Directory\Model\Currency */
18
- private $ currency ;
15
+ /** @var \Magento\Directory\Model\CurrencyFactory */
16
+ private $ currencyFactory ;
19
17
20
18
/**
21
19
* @param \Magento\Framework\Model\Context $context
22
20
* @param \Magento\Framework\Registry $registry
23
21
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
24
22
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
25
- * @param \Magento\Directory\Model\Currency $currency
23
+ * @param \Magento\Directory\Model\CurrencyFactory $currencyFactory
26
24
* @param \Magento\Framework\Model\Resource\AbstractResource $resource
27
25
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
28
26
* @param array $data
@@ -32,14 +30,15 @@ public function __construct(
32
30
\Magento \Framework \Registry $ registry ,
33
31
\Magento \Framework \App \Config \ScopeConfigInterface $ config ,
34
32
\Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ,
35
- \Magento \Directory \Model \Currency $ currency ,
33
+ \Magento \Directory \Model \CurrencyFactory $ currencyFactory ,
36
34
\Magento \Framework \Model \Resource \AbstractResource $ resource = null ,
37
35
\Magento \Framework \Data \Collection \AbstractDb $ resourceCollection = null ,
38
36
array $ data = []
39
37
) {
40
38
parent ::__construct ($ context , $ registry , $ config , $ scopeConfig , $ resource , $ resourceCollection , $ data );
41
- $ this ->currency = $ currency ;
39
+ $ this ->currencyFactory = $ currencyFactory ;
42
40
}
41
+
43
42
/**
44
43
* Check base currency is available in installed currencies
45
44
*
@@ -50,10 +49,12 @@ public function afterSave()
50
49
{
51
50
$ value = $ this ->getValue ();
52
51
if (!in_array ($ value , $ this ->_getInstalledCurrencies ())) {
53
- throw new \Magento \Framework \Exception \LocalizedException (__ ('Sorry, we haven \'t installed the base currency you selected. ' ));
52
+ throw new \Magento \Framework \Exception \LocalizedException (
53
+ __ ('Sorry, we haven \'t installed the base currency you selected. ' ));
54
+
54
55
}
55
56
56
- $ this ->currency ->saveRates ([$ value =>[$ value => 1 ]]);
57
+ $ this ->currencyFactory -> create () ->saveRates ([$ value =>[$ value => 1 ]]);
57
58
return $ this ;
58
59
}
59
60
}
0 commit comments