Skip to content

Commit e15b137

Browse files
committed
ACP2E-1044: Fixer.IO API doesn't work
1 parent cdbc675 commit e15b137

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

app/code/Magento/Directory/Model/Currency/Import/FixerIoApiLayer.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
* Currency rate import model (https://apilayer.com/marketplace/fixer-api)
2020
*/
21-
class FixerIoApiLayer implements \Magento\Directory\Model\Currency\Import\ImportInterface
21+
class FixerIoApiLayer implements ImportInterface
2222
{
2323
private const CURRENCY_CONVERTER_HOST = 'https://api.apilayer.com';
2424
private const CURRENCY_CONVERTER_URL_PATH = '/fixer/latest?'
@@ -27,7 +27,7 @@ class FixerIoApiLayer implements \Magento\Directory\Model\Currency\Import\Import
2727
/**
2828
* @var array
2929
*/
30-
private $_messages = [];
30+
private $messages = [];
3131

3232
/**
3333
* @var HttpClientFactory
@@ -37,7 +37,7 @@ class FixerIoApiLayer implements \Magento\Directory\Model\Currency\Import\Import
3737
/**
3838
* @var CurrencyFactory
3939
*/
40-
private $_currencyFactory;
40+
private $currencyFactory;
4141

4242
/**
4343
* Core scope config
@@ -58,7 +58,7 @@ public function __construct(
5858
ScopeConfigInterface $scopeConfig,
5959
HttpClientFactory $httpClientFactory
6060
) {
61-
$this->_currencyFactory = $currencyFactory;
61+
$this->currencyFactory = $currencyFactory;
6262
$this->scopeConfig = $scopeConfig;
6363
$this->httpClientFactory = $httpClientFactory;
6464
}
@@ -71,7 +71,7 @@ public function __construct(
7171
public function importRates()
7272
{
7373
$data = $this->fetchRates();
74-
$this->_saveRates($data);
74+
$this->saveRates($data);
7575
return $this;
7676
}
7777

@@ -81,8 +81,8 @@ public function importRates()
8181
public function fetchRates()
8282
{
8383
$data = [];
84-
$currencies = $this->_getCurrencyCodes();
85-
$defaultCurrencies = $this->_getDefaultCurrencyCodes();
84+
$currencies = $this->getCurrencyCodes();
85+
$defaultCurrencies = $this->getDefaultCurrencyCodes();
8686

8787
foreach ($defaultCurrencies as $currencyFrom) {
8888
if (!isset($data[$currencyFrom])) {
@@ -99,7 +99,7 @@ public function fetchRates()
9999
*/
100100
public function getMessages()
101101
{
102-
return $this->_messages;
102+
return $this->messages;
103103
}
104104

105105
/**
@@ -114,7 +114,7 @@ private function convertBatch(array $data, string $currencyFrom, array $currenci
114114
{
115115
$accessKey = $this->scopeConfig->getValue('currency/fixerio_apilayer/api_key', ScopeInterface::SCOPE_STORE);
116116
if (empty($accessKey)) {
117-
$this->_messages[] = __('No API Key was specified or an invalid API Key was specified.');
117+
$this->messages[] = __('No API Key was specified or an invalid API Key was specified.');
118118
$data[$currencyFrom] = $this->makeEmptyResponse($currenciesTo);
119119
return $data;
120120
}
@@ -144,7 +144,7 @@ private function convertBatch(array $data, string $currencyFrom, array $currenci
144144
} else {
145145
if (empty($response['rates'][$currencyTo])) {
146146
$message = 'We can\'t retrieve a rate from %1 for %2.';
147-
$this->_messages[] = __($message, self::CURRENCY_CONVERTER_HOST, $currencyTo);
147+
$this->messages[] = __($message, self::CURRENCY_CONVERTER_HOST, $currencyTo);
148148
$data[$currencyFrom][$currencyTo] = null;
149149
} else {
150150
$data[$currencyFrom][$currencyTo] = (double)$response['rates'][$currencyTo];
@@ -160,10 +160,10 @@ private function convertBatch(array $data, string $currencyFrom, array $currenci
160160
* @param array $rates
161161
* @return \Magento\Directory\Model\Currency\Import\FixerIoApiLayer
162162
*/
163-
private function _saveRates(array $rates)
163+
private function saveRates(array $rates)
164164
{
165165
foreach ($rates as $currencyCode => $currencyRates) {
166-
$this->_currencyFactory->create()->setId($currencyCode)->setRates($currencyRates)->save();
166+
$this->currencyFactory->create()->setId($currencyCode)->setRates($currencyRates)->save();
167167
}
168168
return $this;
169169
}
@@ -234,7 +234,7 @@ private function validateResponse(array $response, string $baseCurrency): bool
234234
201 => __('An invalid base currency has been entered.'),
235235
];
236236

237-
$this->_messages[] = $errorCodes[$response['error']['code']] ?? __('Currency rates can\'t be retrieved.');
237+
$this->messages[] = $errorCodes[$response['error']['code']] ?? __('Currency rates can\'t be retrieved.');
238238

239239
return false;
240240
}
@@ -244,18 +244,18 @@ private function validateResponse(array $response, string $baseCurrency): bool
244244
*
245245
* @return array
246246
*/
247-
private function _getCurrencyCodes()
247+
private function getCurrencyCodes()
248248
{
249-
return $this->_currencyFactory->create()->getConfigAllowCurrencies();
249+
return $this->currencyFactory->create()->getConfigAllowCurrencies();
250250
}
251251

252252
/**
253253
* Retrieve default currency codes
254254
*
255255
* @return array
256256
*/
257-
private function _getDefaultCurrencyCodes()
257+
private function getDefaultCurrencyCodes()
258258
{
259-
return $this->_currencyFactory->create()->getConfigBaseCurrencies();
259+
return $this->currencyFactory->create()->getConfigBaseCurrencies();
260260
}
261261
}

0 commit comments

Comments
 (0)