Skip to content

Commit c7ef8c3

Browse files
[Magento Community Engineering] Community Contributions - 2.3-develop
- merged latest code from mainline branch
2 parents 94393ab + 034806f commit c7ef8c3

File tree

16 files changed

+141
-58
lines changed

16 files changed

+141
-58
lines changed

app/code/Magento/AdminNotification/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The Magento_AdminNotification module provides the ability to alert administrator
66

77
Before disabling or uninstalling this module, note that the Magento_Indexer module depends on this module.
88

9-
For information about module installation in Magento 2, see [Enable or disable modules](http://devdocs.magento.com/guides/v2.3/install-gde/install/cli/install-cli-subcommands-enable.html).
9+
For information about module installation in Magento 2, see [Enable or disable modules](https://devdocs.magento.com/guides/v2.3/install-gde/install/cli/install-cli-subcommands-enable.html).
1010

1111
### Events
1212

@@ -21,10 +21,10 @@ This module introduces the following layouts and layout handles in the `view/adm
2121
- `adminhtml_notification_index`
2222
- `adminhtml_notification_block`
2323

24-
For more information about layouts in Magento 2, see the [Layout documentation](http://devdocs.magento.com/guides/v2.3/frontend-dev-guide/layouts/layout-overview.html).
24+
For more information about layouts in Magento 2, see the [Layout documentation](https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/layouts/layout-overview.html).
2525

2626
### UI components
2727

2828
You can extend admin notifications using the `view/adminhtml/ui_component/notification_area.xml` configuration file.
2929

30-
For information about UI components in Magento 2, see [Overview of UI components](http://devdocs.magento.com/guides/v2.3/ui_comp_guide/bk-ui_comps.html).
30+
For information about UI components in Magento 2, see [Overview of UI components](https://devdocs.magento.com/guides/v2.3/ui_comp_guide/bk-ui_comps.html).
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
The Magento_AdvancedPricingImportExport module handles the import and export of the advanced pricing.
1+
# Magento_AdvancedPricingImportExport module
2+
3+
The Magento_AdvancedPricingImportExport module handles the import and export of the advanced pricing.
4+

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

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77

88
namespace Magento\Directory\Model\Currency\Import;
99

10+
/**
11+
* Currency rate import model (From http://free.currencyconverterapi.com/)
12+
*
13+
* Class \Magento\Directory\Model\Currency\Import\CurrencyConverterApi
14+
*/
1015
class CurrencyConverterApi extends AbstractImport
1116
{
1217
/**
1318
* @var string
1419
*/
15-
const CURRENCY_CONVERTER_URL = 'http://free.currencyconverterapi.com/api/v3/convert?q={{CURRENCY_FROM}}_{{CURRENCY_TO}}&compact=ultra'; //@codingStandardsIgnoreLine
20+
const CURRENCY_CONVERTER_URL = 'http://free.currencyconverterapi.com/api/v3/convert?q={{CURRENCY_FROM}}_{{CURRENCY_TO}}&compact=ultra&apiKey={{API_KEY}}'; //@codingStandardsIgnoreLine
1621

1722
/**
1823
* Http Client Factory
@@ -46,7 +51,7 @@ public function __construct(
4651
}
4752

4853
/**
49-
* {@inheritdoc}
54+
* @inheritdoc
5055
*/
5156
public function fetchRates()
5257
{
@@ -74,23 +79,25 @@ public function fetchRates()
7479
*/
7580
private function convertBatch($data, $currencyFrom, $currenciesTo)
7681
{
82+
$apiKey = $this->scopeConfig->getValue(
83+
'currency/currencyconverterapi/api_key',
84+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
85+
);
86+
if (!$apiKey) {
87+
$this->_messages[] = __('No API Key was specified.');
88+
return $data;
89+
}
7790
foreach ($currenciesTo as $to) {
91+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
7892
set_time_limit(0);
7993
try {
8094
$url = str_replace('{{CURRENCY_FROM}}', $currencyFrom, self::CURRENCY_CONVERTER_URL);
8195
$url = str_replace('{{CURRENCY_TO}}', $to, $url);
82-
$response = $this->getServiceResponse($url);
96+
$url = str_replace('{{API_KEY}}', $apiKey, $url);
8397
if ($currencyFrom == $to) {
8498
$data[$currencyFrom][$to] = $this->_numberFormat(1);
8599
} else {
86-
if (empty($response)) {
87-
$this->_messages[] = __('We can\'t retrieve a rate from %1 for %2.', $url, $to);
88-
$data[$currencyFrom][$to] = null;
89-
} else {
90-
$data[$currencyFrom][$to] = $this->_numberFormat(
91-
(double)$response[$currencyFrom . '_' . $to]
92-
);
93-
}
100+
$data[$currencyFrom][$to] = $this->getCurrencyRate($currencyFrom, $to, $url);
94101
}
95102
} finally {
96103
ini_restore('max_execution_time');
@@ -100,6 +107,36 @@ private function convertBatch($data, $currencyFrom, $currenciesTo)
100107
return $data;
101108
}
102109

110+
/**
111+
* Get currency rate from api
112+
*
113+
* @param string $currencyFrom
114+
* @param string $to
115+
* @param string $url
116+
* @return double
117+
*/
118+
private function getCurrencyRate($currencyFrom, $to, $url)
119+
{
120+
$rate = null;
121+
$response = $this->getServiceResponse($url);
122+
if (empty($response)) {
123+
$this->_messages[] = __('We can\'t retrieve a rate from %1 for %2.', $url, $to);
124+
$rate = null;
125+
} else {
126+
if (isset($response['error']) && $response['error']) {
127+
if (!in_array($response['error'], $this->_messages)) {
128+
$this->_messages[] = $response['error'];
129+
}
130+
$rate = null;
131+
} else {
132+
$rate = $this->_numberFormat(
133+
(double)$response[$currencyFrom . '_' . $to]
134+
);
135+
}
136+
}
137+
return $rate;
138+
}
139+
103140
/**
104141
* Get Fixer.io service response
105142
*
@@ -137,7 +174,7 @@ private function getServiceResponse($url, $retry = 0)
137174
}
138175

139176
/**
140-
* {@inheritdoc}
177+
* @inheritdoc
141178
*/
142179
protected function _convert($currencyFrom, $currencyTo)
143180
{

app/code/Magento/Directory/etc/adminhtml/system.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@
4747
</group>
4848
<group id="currencyconverterapi" translate="label" sortOrder="45" showInDefault="1" showInWebsite="0" showInStore="0">
4949
<label>Currency Converter API</label>
50-
<field id="timeout" translate="label" type="text" sortOrder="0" showInDefault="1" showInWebsite="0" showInStore="0">
50+
<field id="api_key" translate="label" type="obscure" sortOrder="0" showInDefault="1" showInWebsite="0" showInStore="0">
51+
<label>API Key</label>
52+
<config_path>currency/currencyconverterapi/api_key</config_path>
53+
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
54+
</field>
55+
<field id="timeout" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
5156
<label>Connection Timeout in Seconds</label>
5257
</field>
5358
</group>

app/code/Magento/Directory/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
</fixerio>
2525
<currencyconverterapi>
2626
<timeout>100</timeout>
27+
<api_key backend_model="Magento\Config\Model\Config\Backend\Encrypted" />
2728
</currencyconverterapi>
2829
<import>
2930
<enabled>0</enabled>

app/code/Magento/Directory/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ Service,Service
5252
"The """%1"" is not allowed as base currency for your subscription plan.","The """%1"" is not allowed as base currency for your subscription plan."
5353
"An invalid base currency has been entered.","An invalid base currency has been entered."
5454
"Currency rates can't be retrieved.","Currency rates can't be retrieved."
55+
"No API Key was specified.","No API Key was specified."

app/code/Magento/Sitemap/Model/Sitemap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@ protected function _initSitemapItems()
362362
self::OPEN_TAG_KEY => '<?xml version="1.0" encoding="UTF-8"?>' .
363363
PHP_EOL .
364364
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' .
365-
' xmlns:content="http://www.google.com/schemas/sitemap-content/1.0"' .
366365
' xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">' .
367366
PHP_EOL,
368367
self::CLOSE_TAG_KEY => '</urlset>',

app/code/Magento/Sitemap/Test/Unit/Model/_files/sitemap-1-1.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
-->
88
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
9-
xmlns:content="http://www.google.com/schemas/sitemap-content/1.0"
109
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
1110
<url>
1211
<loc>http://store.com/category.html</loc>

app/code/Magento/Sitemap/Test/Unit/Model/_files/sitemap-1-2.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
-->
88
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
9-
xmlns:content="http://www.google.com/schemas/sitemap-content/1.0"
109
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
1110
<url>
1211
<loc>http://store.com/category/sub-category.html</loc>

app/code/Magento/Sitemap/Test/Unit/Model/_files/sitemap-1-3.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
-->
88
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
9-
xmlns:content="http://www.google.com/schemas/sitemap-content/1.0"
109
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
1110
<url>
1211
<loc>http://store.com/product.html</loc>

0 commit comments

Comments
 (0)