Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CurrencyInformationAcquirer.php
Go to the documentation of this file.
1 <?php
7 
12 {
17 
22 
26  protected $storeManager;
27 
33  public function __construct(
34  \Magento\Directory\Model\Data\CurrencyInformationFactory $currencyInformationFactory,
35  \Magento\Directory\Model\Data\ExchangeRateFactory $exchangeRateFactory,
37  ) {
38  $this->currencyInformationFactory = $currencyInformationFactory;
39  $this->exchangeRateFactory = $exchangeRateFactory;
40  $this->storeManager = $storeManager;
41  }
42 
46  public function getCurrencyInfo()
47  {
48  $currencyInfo = $this->currencyInformationFactory->create();
49 
51  $store = $this->storeManager->getStore();
52 
53  $currencyInfo->setBaseCurrencyCode($store->getBaseCurrency()->getCode());
54  $currencyInfo->setBaseCurrencySymbol($store->getBaseCurrency()->getCurrencySymbol());
55 
56  $currencyInfo->setDefaultDisplayCurrencyCode($store->getDefaultCurrency()->getCode());
57  $currencyInfo->setDefaultDisplayCurrencySymbol($store->getDefaultCurrency()->getCurrencySymbol());
58 
59  $currencyInfo->setAvailableCurrencyCodes($store->getAvailableCurrencyCodes(true));
60 
61  $exchangeRates = [];
62  foreach ($store->getAvailableCurrencyCodes(true) as $currencyCode) {
63  $exchangeRate = $this->exchangeRateFactory->create();
64  $exchangeRate->setRate($store->getBaseCurrency()->getRate($currencyCode));
65  $exchangeRate->setCurrencyTo($currencyCode);
66  $exchangeRates[] = $exchangeRate;
67  }
68  $currencyInfo->setExchangeRates($exchangeRates);
69 
70  return $currencyInfo;
71  }
72 }
__construct(\Magento\Directory\Model\Data\CurrencyInformationFactory $currencyInformationFactory, \Magento\Directory\Model\Data\ExchangeRateFactory $exchangeRateFactory, \Magento\Store\Model\StoreManagerInterface $storeManager)