1414
1515class Base extends AbstractCurrency
1616{
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+ }
1743 /**
1844 * Check base currency is available in installed currencies
1945 *
@@ -22,9 +48,12 @@ class Base extends AbstractCurrency
2248 */
2349 public function afterSave ()
2450 {
25- if (!in_array ($ this ->getValue (), $ this ->_getInstalledCurrencies ())) {
51+ $ value = $ this ->getValue ();
52+ if (!in_array ($ value , $ this ->_getInstalledCurrencies ())) {
2653 throw new \Magento \Framework \Exception \LocalizedException (__ ('Sorry, we haven \'t installed the base currency you selected. ' ));
2754 }
55+
56+ $ this ->currency ->saveRates ([$ value =>[$ value => 1 ]]);
2857 return $ this ;
2958 }
3059}
0 commit comments