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