namespace and api call
This commit is contained in:
parent
d2a16d9789
commit
42742bb050
|
@ -4,8 +4,8 @@
|
|||
* Since: 2018
|
||||
*/
|
||||
|
||||
namespace Flancer32\FreeRates;
|
||||
namespace Oreolek\MagentoLym;
|
||||
class Config
|
||||
{
|
||||
const MODULE = 'Flancer32_FreeRates';
|
||||
}
|
||||
const MODULE = 'Oreolek_MagentoLym';
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* Since: 2018
|
||||
*/
|
||||
|
||||
namespace Flancer32\FreeRates\Helper;
|
||||
namespace Oreolek\MagentoLym\Helper;
|
||||
|
||||
|
||||
class Config
|
||||
|
@ -24,7 +24,7 @@ class Config
|
|||
*/
|
||||
public function getDelay()
|
||||
{
|
||||
$result = (int)$this->scopeConfig->getValue('currency/fcc/delay');
|
||||
$result = (int)$this->scopeConfig->getValue('currency/lym/delay');
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ class Config
|
|||
*/
|
||||
public function getTimeout()
|
||||
{
|
||||
$result = (int)$this->scopeConfig->getValue('currency/fcc/timeout');
|
||||
$result = (int)$this->scopeConfig->getValue('currency/lym/timeout');
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* Since: 2018
|
||||
*/
|
||||
|
||||
namespace Flancer32\FreeRates\Model\Currency\Import;
|
||||
namespace Oreolek\MagentoLym\Model\Currency\Import;
|
||||
|
||||
|
||||
class Fcc
|
||||
|
@ -15,9 +15,9 @@ class Fcc
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
const CURRENCY_CONVERTER_URL = 'https://free.currencyconverterapi.com/api/v3/convert?q={{CURRENCY_FROM}}_{{CURRENCY_TO}}';
|
||||
const CURRENCY_CONVERTER_URL = 'https://coindata.lympo.io/etherspy/public/api/fetch/currency/market_data?currency=lympo&ticker_symbol=lym';
|
||||
|
||||
/** @var \Flancer32\FreeRates\Helper\Config */
|
||||
/** @var \Oreolek\MagentoLym\Helper\Config */
|
||||
private $hlpCfg;
|
||||
/** @var \Magento\Framework\HTTP\ZendClient */
|
||||
private $httpClient;
|
||||
|
@ -31,7 +31,7 @@ class Fcc
|
|||
\Magento\Framework\HTTP\ZendClient $httpClient,
|
||||
\Magento\Directory\Model\CurrencyFactory $currencyFactory,
|
||||
\Magento\Framework\Json\Helper\Data $jsonHelper,
|
||||
\Flancer32\FreeRates\Helper\Config $hlpCfg
|
||||
\Oreolek\MagentoLym\Helper\Config $hlpCfg
|
||||
) {
|
||||
parent::__construct($currencyFactory);
|
||||
$this->logger = $logger;
|
||||
|
@ -49,8 +49,7 @@ class Fcc
|
|||
protected function _convert($currencyFrom, $currencyTo, $retry = 0)
|
||||
{
|
||||
$result = null;
|
||||
$url = str_replace('{{CURRENCY_FROM}}', $currencyFrom, self::CURRENCY_CONVERTER_URL);
|
||||
$url = str_replace('{{CURRENCY_TO}}', $currencyTo, $url);
|
||||
$url = self::CURRENCY_CONVERTER_URL;
|
||||
$this->logger->info("Currency rates request: $url");
|
||||
$delay = $this->hlpCfg->getDelay();
|
||||
$timeout = $this->hlpCfg->getTimeout();
|
||||
|
@ -60,14 +59,12 @@ class Fcc
|
|||
$this->httpClient->setConfig(['timeout' => $timeout,]);
|
||||
$response = $this->httpClient->request('GET');
|
||||
$body = $response->getBody();
|
||||
$resultKey = $currencyFrom . '_' . $currencyTo;
|
||||
$data = $this->jsonHelper->jsonDecode($body);
|
||||
$results = $data['results'][$resultKey];
|
||||
$queryCount = $data['query']['count'];
|
||||
if (!$queryCount && !isset($results)) {
|
||||
$results = $data['results']['currency_market_data'];
|
||||
if (!isset($results)) {
|
||||
$this->_messages[] = __('We can\'t retrieve a rate from %1.', $url);
|
||||
} else {
|
||||
$result = (float)$results['val'];
|
||||
$result = (float)$results[$currencyFrom]['current_price'];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
if ($retry == 0) {
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
# mage2_ext_free_rates
|
||||
# LYM currency
|
||||
|
||||
Magento 2: Currency converter to get rates from https://free.currencyconverterapi.com/
|
||||
|
||||
[Based on "krybbio" code](https://magento.stackexchange.com/a/228671/33058).
|
||||
Magento 2: LYM Currency
|
||||
|
||||
```
|
||||
$ composer require flancer32/mage2_ext_free_rates
|
||||
$ composer require oreolek/magentolym
|
||||
$ ./bin/magento setup:upgrade
|
||||
$ ./bin/magento deploy:mode:set developer
|
||||
$ ./bin/magento deploy:mode:set production
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
{
|
||||
"name": "flancer32/mage2_ext_free_rates",
|
||||
"description": "Magento 2: Currency converter to get rates from https://free.currencyconverterapi.com/",
|
||||
"name": "oreolek/magentolym",
|
||||
"description": "Magento 2: LYM Currency",
|
||||
"type": "magento2-module",
|
||||
"homepage": "https://github.com/flancer32/mage2_ext_free_rates",
|
||||
"license": "GPL-3.0-only",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Alex Gusev",
|
||||
"email": "alex@flancer64.com"
|
||||
},
|
||||
{
|
||||
"name": "Alex Yakovlev",
|
||||
"email": "keloero@oreolek.ru"
|
||||
}
|
||||
],
|
||||
"require": {},
|
||||
|
@ -16,7 +19,7 @@
|
|||
"registration.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Flancer32\\FreeRates\\": ""
|
||||
"Oreolek\\MagentoLym\\": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
|
||||
<system>
|
||||
<section id="currency">
|
||||
<group id="fcc" translate="label"
|
||||
<group id="lym" translate="label"
|
||||
sortOrder="41" showInDefault="1" showInWebsite="0" showInStore="0">
|
||||
<label>Free Currency Converter</label>
|
||||
<label>LYM Currency</label>
|
||||
<field id="timeout" translate="label" type="text"
|
||||
sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
|
||||
<label>Connection Timeout in Seconds</label>
|
||||
|
@ -17,4 +17,4 @@
|
|||
</group>
|
||||
</section>
|
||||
</system>
|
||||
</config>
|
||||
</config>
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
|
||||
<default>
|
||||
<currency>
|
||||
<fcc>
|
||||
<lym>
|
||||
<timeout>100</timeout>
|
||||
<delay>1</delay>
|
||||
</fcc>
|
||||
</lym>
|
||||
</currency>
|
||||
</default>
|
||||
</config>
|
||||
</config>
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
<type name="Magento\Directory\Model\Currency\Import\Config">
|
||||
<arguments>
|
||||
<argument name="servicesConfig" xsi:type="array">
|
||||
<item name="fcc" xsi:type="array">
|
||||
<item name="label" xsi:type="string">Free Currency Converter</item>
|
||||
<item name="class" xsi:type="string">Flancer32\FreeRates\Model\Currency\Import\Fcc</item>
|
||||
<item name="lym" xsi:type="array">
|
||||
<item name="label" xsi:type="string">LYM Currency</item>
|
||||
<item name="class" xsi:type="string">Oreolek\MagentoLym\Model\Currency\Import\Fcc</item>
|
||||
</item>
|
||||
</argument>
|
||||
</arguments>
|
||||
</type>
|
||||
|
||||
</config>
|
||||
</config>
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
<config
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
|
||||
<module name="Flancer32_FreeRates" setup_version="0.1.0">
|
||||
<module name="Oreolek_MagentoLym" setup_version="0.1.0">
|
||||
<sequence>
|
||||
<module name="Magento_Directory"/>
|
||||
</sequence>
|
||||
</module>
|
||||
</config>
|
||||
</config>
|
||||
|
|
|
@ -5,6 +5,6 @@
|
|||
*/
|
||||
\Magento\Framework\Component\ComponentRegistrar::register(
|
||||
\Magento\Framework\Component\ComponentRegistrar::MODULE,
|
||||
\Flancer32\FreeRates\Config::MODULE,
|
||||
\Oreolek\MagentoLym\Config::MODULE,
|
||||
__DIR__
|
||||
);
|
||||
);
|
||||
|
|
Reference in a new issue