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