AbstractCurrency.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * \Directory currency abstract backend model
  8. *
  9. * Allows dispatching before and after events for each controller action
  10. *
  11. * @author Magento Core Team <core@magentocommerce.com>
  12. */
  13. namespace Magento\Config\Model\Config\Backend\Currency;
  14. /**
  15. * Base currency class
  16. *
  17. * @api
  18. * @since 100.0.2
  19. */
  20. abstract class AbstractCurrency extends \Magento\Framework\App\Config\Value
  21. {
  22. /**
  23. * Retrieve allowed currencies for current scope
  24. *
  25. * @return array
  26. */
  27. protected function _getAllowedCurrencies()
  28. {
  29. $allowValue = $this->getData('groups/options/fields/allow/value');
  30. $allowedCurrencies = $allowValue === null || $this->getData('groups/options/fields/allow/inherit')
  31. ? explode(
  32. ',',
  33. (string)$this->_config->getValue(
  34. \Magento\Directory\Model\Currency::XML_PATH_CURRENCY_ALLOW,
  35. $this->getScope(),
  36. $this->getScopeId()
  37. )
  38. )
  39. : (array) $allowValue;
  40. return $allowedCurrencies;
  41. }
  42. /**
  43. * Retrieve Installed Currencies
  44. *
  45. * @return string[]
  46. */
  47. protected function _getInstalledCurrencies()
  48. {
  49. return explode(
  50. ',',
  51. $this->_config->getValue(
  52. 'system/currency/installed',
  53. \Magento\Store\Model\ScopeInterface::SCOPE_STORE
  54. )
  55. );
  56. }
  57. /**
  58. * Retrieve Base Currency value for current scope
  59. *
  60. * @return string
  61. */
  62. protected function _getCurrencyBase()
  63. {
  64. $value = $this->getData('groups/options/fields/base/value');
  65. if (!$this->isFormData() || !$value) {
  66. $value = $this->_config->getValue(
  67. \Magento\Directory\Model\Currency::XML_PATH_CURRENCY_BASE,
  68. $this->getScope(),
  69. $this->getScopeId()
  70. );
  71. }
  72. return (string)$value;
  73. }
  74. /**
  75. * Retrieve Default display Currency value for current scope
  76. *
  77. * @return string
  78. */
  79. protected function _getCurrencyDefault()
  80. {
  81. if (!$this->isFormData() || !($value = $this->getData('groups/options/fields/default/value'))) {
  82. $value = $this->_config->getValue(
  83. \Magento\Directory\Model\Currency::XML_PATH_CURRENCY_DEFAULT,
  84. $this->getScope(),
  85. $this->getScopeId()
  86. );
  87. }
  88. return (string)$value;
  89. }
  90. /**
  91. * Check whether field saved from Admin form with other currency data or as single field, e.g. from CLI command
  92. *
  93. * @return bool True in case when field was saved from Admin form
  94. */
  95. private function isFormData()
  96. {
  97. return $this->getData('groups/options/fields') !== null;
  98. }
  99. }