DefaultCurrency.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Config Directory currency backend model
  8. * Allows dispatching before and after events for each controller action
  9. */
  10. namespace Magento\Config\Model\Config\Backend\Currency;
  11. /**
  12. * @api
  13. * @since 100.0.2
  14. */
  15. class DefaultCurrency extends AbstractCurrency
  16. {
  17. /**
  18. * Check default currency is available in installed currencies
  19. * Check default currency is available in allowed currencies
  20. *
  21. * @return $this
  22. * @throws \Magento\Framework\Exception\LocalizedException
  23. */
  24. public function afterSave()
  25. {
  26. if (!in_array($this->getValue(), $this->_getInstalledCurrencies())) {
  27. throw new \Magento\Framework\Exception\LocalizedException(
  28. __('Sorry, we haven\'t installed the default display currency you selected.')
  29. );
  30. }
  31. if (!in_array($this->getValue(), $this->_getAllowedCurrencies())) {
  32. throw new \Magento\Framework\Exception\LocalizedException(
  33. __('Sorry, the default display currency you selected is not available in allowed currencies.')
  34. );
  35. }
  36. return parent::afterSave();
  37. }
  38. }