SaveRates.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currency;
  8. use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
  9. class SaveRates extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Currency implements HttpPostActionInterface
  10. {
  11. /**
  12. * Save rates action
  13. *
  14. * @return void
  15. */
  16. public function execute()
  17. {
  18. $data = $this->getRequest()->getParam('rate');
  19. if (is_array($data)) {
  20. try {
  21. foreach ($data as $currencyCode => $rate) {
  22. foreach ($rate as $currencyTo => $value) {
  23. $value = abs($this->_objectManager->get(
  24. \Magento\Framework\Locale\FormatInterface::class
  25. )->getNumber($value));
  26. $data[$currencyCode][$currencyTo] = $value;
  27. if ($value == 0) {
  28. $this->messageManager->addWarning(
  29. __('Please correct the input data for "%1 => %2" rate.', $currencyCode, $currencyTo)
  30. );
  31. }
  32. }
  33. }
  34. $this->_objectManager->create(\Magento\Directory\Model\Currency::class)->saveRates($data);
  35. $this->messageManager->addSuccess(__('All valid rates have been saved.'));
  36. } catch (\Exception $e) {
  37. $this->messageManager->addError($e->getMessage());
  38. }
  39. }
  40. $this->_redirect('adminhtml/*/');
  41. }
  42. }