17 const CRON_STRING_PATH =
'crontab/default/jobs/currency_rates_update/schedule/cron_expr';
72 \
Magento\Framework\Mail\Template\TransportBuilder $transportBuilder,
74 \
Magento\Directory\Model\CurrencyFactory $currencyFactory,
77 $this->_importFactory = $importFactory;
78 $this->_scopeConfig = $scopeConfig;
79 $this->_transportBuilder = $transportBuilder;
81 $this->_currencyFactory = $currencyFactory;
94 if (!$this->_scopeConfig->getValue(
97 ) || !$this->_scopeConfig->getValue(
98 self::CRON_STRING_PATH,
107 $service = $this->_scopeConfig->getValue(
108 self::IMPORT_SERVICE,
113 $importModel = $this->_importFactory->create(
$service);
114 $rates = $importModel->fetchRates();
115 $errors = $importModel->getMessages();
116 }
catch (\Exception $e) {
117 $importWarnings[] =
__(
'FATAL ERROR:') .
' ' 118 .
__(
"The import model can't be initialized. Verify the model and try again.");
122 $importWarnings[] =
__(
'FATAL ERROR:') .
' ' .
__(
'Please specify the correct Import Service.');
127 $importWarnings[] =
__(
'WARNING:') .
' ' . $error;
131 $errorRecipient = $this->_scopeConfig->getValue(
132 self::XML_PATH_ERROR_RECIPIENT,
135 if (
sizeof($importWarnings) == 0) {
136 $this->_currencyFactory->create()->saveRates(
$rates);
137 }
elseif ($errorRecipient) {
139 $this->inlineTranslation->suspend();
141 $this->_transportBuilder->setTemplateIdentifier(
142 $this->_scopeConfig->getValue(
143 self::XML_PATH_ERROR_TEMPLATE,
146 )->setTemplateOptions(
152 [
'warnings' => join(
"\n", $importWarnings)]
154 $this->_scopeConfig->getValue(
155 self::XML_PATH_ERROR_IDENTITY,
158 )->addTo($errorRecipient);
159 $transport = $this->_transportBuilder->getTransport();
160 $transport->sendMessage();
162 $this->inlineTranslation->resume();
const XML_PATH_ERROR_RECIPIENT
elseif(isset( $params[ 'redirect_parent']))
const XML_PATH_ERROR_IDENTITY
const XML_PATH_ERROR_TEMPLATE
__construct(\Magento\Directory\Model\Currency\Import\Factory $importFactory, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Directory\Model\CurrencyFactory $currencyFactory, \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation)
scheduledUpdateCurrencyRates($schedule)