Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SaveRates.php
Go to the documentation of this file.
1 <?php
9 
10 use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
11 
12 class SaveRates extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Currency implements HttpPostActionInterface
13 {
19  public function execute()
20  {
21  $data = $this->getRequest()->getParam('rate');
22  if (is_array($data)) {
23  try {
24  foreach ($data as $currencyCode => $rate) {
25  foreach ($rate as $currencyTo => $value) {
26  $value = abs($this->_objectManager->get(
27  \Magento\Framework\Locale\FormatInterface::class
28  )->getNumber($value));
29  $data[$currencyCode][$currencyTo] = $value;
30  if ($value == 0) {
31  $this->messageManager->addWarning(
32  __('Please correct the input data for "%1 => %2" rate.', $currencyCode, $currencyTo)
33  );
34  }
35  }
36  }
37 
38  $this->_objectManager->create(\Magento\Directory\Model\Currency::class)->saveRates($data);
39  $this->messageManager->addSuccess(__('All valid rates have been saved.'));
40  } catch (\Exception $e) {
41  $this->messageManager->addError($e->getMessage());
42  }
43  }
44 
45  $this->_redirect('adminhtml/*/');
46  }
47 }
__()
Definition: __.php:13
$value
Definition: gender.phtml:16