Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions
CurrencyConverterApi Class Reference
Inheritance diagram for CurrencyConverterApi:
AbstractImport ImportInterface

Public Member Functions

 __construct (\Magento\Directory\Model\CurrencyFactory $currencyFactory, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\HTTP\ZendClientFactory $httpClientFactory)
 
 fetchRates ()
 
- Public Member Functions inherited from AbstractImport
 __construct (\Magento\Directory\Model\CurrencyFactory $currencyFactory)
 
 importRates ()
 
 fetchRates ()
 
 getMessages ()
 

Data Fields

const CURRENCY_CONVERTER_URL = 'http://free.currencyconverterapi.com/api/v3/convert?q={{CURRENCY_FROM}}_{{CURRENCY_TO}}&compact=ultra'
 

Protected Member Functions

 _convert ($currencyFrom, $currencyTo)
 
- Protected Member Functions inherited from AbstractImport
 _getCurrencyCodes ()
 
 _getDefaultCurrencyCodes ()
 
 _convert ($currencyFrom, $currencyTo)
 
 _saveRates ($rates)
 
 _numberFormat ($number)
 

Additional Inherited Members

- Protected Attributes inherited from AbstractImport
 $_messages = []
 
 $_currencyFactory
 

Detailed Description

Definition at line 10 of file CurrencyConverterApi.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Directory\Model\CurrencyFactory  $currencyFactory,
\Magento\Framework\App\Config\ScopeConfigInterface  $scopeConfig,
\Magento\Framework\HTTP\ZendClientFactory  $httpClientFactory 
)

Initialize dependencies

Parameters
\Magento\Directory\Model\CurrencyFactory$currencyFactory
\Magento\Framework\App\Config\ScopeConfigInterface$scopeConfig
\Magento\Framework\HTTP\ZendClientFactory$httpClientFactory

Definition at line 38 of file CurrencyConverterApi.php.

42  {
43  parent::__construct($currencyFactory);
44  $this->scopeConfig = $scopeConfig;
45  $this->httpClientFactory = $httpClientFactory;
46  }

Member Function Documentation

◆ _convert()

_convert (   $currencyFrom,
  $currencyTo 
)
protected

{}

Definition at line 142 of file CurrencyConverterApi.php.

143  {
144  return 1;
145  }

◆ fetchRates()

fetchRates ( )

{Fetch rates

Returns
array
}

Implements ImportInterface.

Definition at line 51 of file CurrencyConverterApi.php.

52  {
53  $data = [];
54  $currencies = $this->_getCurrencyCodes();
55  $defaultCurrencies = $this->_getDefaultCurrencyCodes();
56 
57  foreach ($defaultCurrencies as $currencyFrom) {
58  if (!isset($data[$currencyFrom])) {
59  $data[$currencyFrom] = [];
60  }
61  $data = $this->convertBatch($data, $currencyFrom, $currencies);
62  ksort($data[$currencyFrom]);
63  }
64  return $data;
65  }

Field Documentation

◆ CURRENCY_CONVERTER_URL

const CURRENCY_CONVERTER_URL = 'http://free.currencyconverterapi.com/api/v3/convert?q={{CURRENCY_FROM}}_{{CURRENCY_TO}}&compact=ultra'

Definition at line 15 of file CurrencyConverterApi.php.


The documentation for this class was generated from the following file: