/** * Check base currency is available in installed currencies * * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ public function afterSave() { $value = $this->getValue(); if (!in_array($value, $this->_getInstalledCurrencies())) { throw new \Magento\Framework\Exception\LocalizedException(__('Sorry, we haven\'t installed the base currency you selected.')); } $this->currencyFactory->create()->saveRates([$value => [$value => 1]]); return parent::afterSave(); }
/** * Check default currency is available in installed currencies * Check default currency is available in allowed currencies * * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ public function afterSave() { if (!in_array($this->getValue(), $this->_getInstalledCurrencies())) { throw new \Magento\Framework\Exception\LocalizedException(__('Sorry, we haven\'t installed the default display currency you selected.')); } if (!in_array($this->getValue(), $this->_getAllowedCurrencies())) { throw new \Magento\Framework\Exception\LocalizedException(__('Sorry, the default display currency you selected is not available in allowed currencies.')); } return parent::afterSave(); }
/** * Check is isset default display currency in allowed currencies * Check allowed currencies is available in installed currencies * * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ public function afterSave() { $exceptions = []; foreach ($this->_getAllowedCurrencies() as $currencyCode) { if (!in_array($currencyCode, $this->_getInstalledCurrencies())) { $exceptions[] = __('Selected allowed currency "%1" is not available in installed currencies.', $this->_localeCurrency->getCurrency($currencyCode)->getName()); } } if (!in_array($this->_getCurrencyDefault(), $this->_getAllowedCurrencies())) { $exceptions[] = __('Default display currency "%1" is not available in allowed currencies.', $this->_localeCurrency->getCurrency($this->_getCurrencyDefault())->getName()); } if ($exceptions) { throw new \Magento\Framework\Exception\LocalizedException(__(join("\n", $exceptions))); } return parent::afterSave(); }