Data.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Adminhtml\Order\Create;
  7. use Magento\Framework\Pricing\PriceCurrencyInterface;
  8. /**
  9. * Order create data
  10. *
  11. * @api
  12. * @author Magento Core Team <core@magentocommerce.com>
  13. * @since 100.0.2
  14. */
  15. class Data extends \Magento\Sales\Block\Adminhtml\Order\Create\AbstractCreate
  16. {
  17. /**
  18. * Currency factory
  19. *
  20. * @var \Magento\Directory\Model\CurrencyFactory
  21. */
  22. protected $_currencyFactory;
  23. /**
  24. * @var \Magento\Framework\Locale\CurrencyInterface
  25. */
  26. protected $_localeCurrency;
  27. /**
  28. * @param \Magento\Backend\Block\Template\Context $context
  29. * @param \Magento\Backend\Model\Session\Quote $sessionQuote
  30. * @param \Magento\Sales\Model\AdminOrder\Create $orderCreate
  31. * @param PriceCurrencyInterface $priceCurrency
  32. * @param \Magento\Directory\Model\CurrencyFactory $currencyFactory
  33. * @param \Magento\Framework\Locale\CurrencyInterface $localeCurrency
  34. * @param array $data
  35. */
  36. public function __construct(
  37. \Magento\Backend\Block\Template\Context $context,
  38. \Magento\Backend\Model\Session\Quote $sessionQuote,
  39. \Magento\Sales\Model\AdminOrder\Create $orderCreate,
  40. PriceCurrencyInterface $priceCurrency,
  41. \Magento\Directory\Model\CurrencyFactory $currencyFactory,
  42. \Magento\Framework\Locale\CurrencyInterface $localeCurrency,
  43. array $data = []
  44. ) {
  45. $this->_currencyFactory = $currencyFactory;
  46. $this->_localeCurrency = $localeCurrency;
  47. parent::__construct($context, $sessionQuote, $orderCreate, $priceCurrency, $data);
  48. }
  49. /**
  50. * Retrieve available currency codes
  51. *
  52. * @return string[]
  53. */
  54. public function getAvailableCurrencies()
  55. {
  56. $dirtyCodes = $this->getStore()->getAvailableCurrencyCodes();
  57. $codes = [];
  58. if (is_array($dirtyCodes) && count($dirtyCodes)) {
  59. $rates = $this->_currencyFactory->create()->getCurrencyRates(
  60. $this->_storeManager->getStore()->getBaseCurrency(),
  61. $dirtyCodes
  62. );
  63. foreach ($dirtyCodes as $code) {
  64. if (isset($rates[$code]) || $code == $this->_storeManager->getStore()->getBaseCurrencyCode()) {
  65. $codes[] = $code;
  66. }
  67. }
  68. }
  69. return $codes;
  70. }
  71. /**
  72. * Retrieve currency name by code
  73. *
  74. * @param string $code
  75. * @return string
  76. */
  77. public function getCurrencyName($code)
  78. {
  79. return $this->_localeCurrency->getCurrency($code)->getName();
  80. }
  81. /**
  82. * Retrieve currency name by code
  83. *
  84. * @param string $code
  85. * @return string
  86. */
  87. public function getCurrencySymbol($code)
  88. {
  89. $currency = $this->_localeCurrency->getCurrency($code);
  90. return $currency->getSymbol() ? $currency->getSymbol() : $currency->getShortName();
  91. }
  92. /**
  93. * Retrieve current order currency code
  94. *
  95. * @return string
  96. */
  97. public function getCurrentCurrencyCode()
  98. {
  99. return $this->getStore()->getCurrentCurrencyCode();
  100. }
  101. }