44 * See COPYING.txt for license details.
55 */
66
7- // @codingStandardsIgnoreFile
8-
97/**
108 * Backend Directory currency backend model
119 * Allows dispatching before and after events for each controller action
1412
1513class Base extends AbstractCurrency
1614{
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+
1742 /**
1843 * Check base currency is available in installed currencies
1944 *
@@ -22,9 +47,14 @@ class Base extends AbstractCurrency
2247 */
2348 public function afterSave ()
2449 {
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+ );
2755 }
56+
57+ $ this ->currencyFactory ->create ()->saveRates ([$ value =>[$ value => 1 ]]);
2858 return $ this ;
2959 }
3060}
0 commit comments