Skip to content

Commit 807402c

Browse files
committed
Merge branch '2.3-develop' of https://github.com/magento/magento2ce into pr_vk_2019_08_16
2 parents 0c7f3b8 + 034806f commit 807402c

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>

app/code/Magento/Sitemap/Test/Unit/Model/_files/sitemap-1-4.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/product2.html</loc>

app/code/Magento/Sitemap/Test/Unit/Model/_files/sitemap-single.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/UrlRewrite/Model/Storage/DbStorage.php

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ class DbStorage extends AbstractStorage
4949
private $logger;
5050

5151
/**
52-
* @param UrlRewriteFactory $urlRewriteFactory
53-
* @param DataObjectHelper $dataObjectHelper
54-
* @param ResourceConnection $resource
52+
* @param UrlRewriteFactory $urlRewriteFactory
53+
* @param DataObjectHelper $dataObjectHelper
54+
* @param ResourceConnection $resource
5555
* @param LoggerInterface|null $logger
5656
*/
5757
public function __construct(
@@ -71,7 +71,7 @@ public function __construct(
7171
/**
7272
* Prepare select statement for specific filter
7373
*
74-
* @param array $data
74+
* @param array $data
7575
* @return Select
7676
*/
7777
protected function prepareSelect(array $data)
@@ -106,12 +106,14 @@ protected function doFindOneByData(array $data)
106106

107107
$requestPath = $data[UrlRewrite::REQUEST_PATH];
108108
$decodedRequestPath = urldecode($requestPath);
109-
$data[UrlRewrite::REQUEST_PATH] = array_unique([
109+
$data[UrlRewrite::REQUEST_PATH] = array_unique(
110+
[
110111
rtrim($requestPath, '/'),
111112
rtrim($requestPath, '/') . '/',
112113
rtrim($decodedRequestPath, '/'),
113114
rtrim($decodedRequestPath, '/') . '/',
114-
]);
115+
]
116+
);
115117

116118
$resultsFromDb = $this->connection->fetchAll($this->prepareSelect($data));
117119
if ($resultsFromDb) {
@@ -128,8 +130,8 @@ protected function doFindOneByData(array $data)
128130
/**
129131
* Extract most relevant url rewrite from url rewrites list
130132
*
131-
* @param string $requestPath
132-
* @param array $urlRewrites
133+
* @param string $requestPath
134+
* @param array $urlRewrites
133135
* @return array|null
134136
*/
135137
private function extractMostRelevantUrlRewrite(string $requestPath, array $urlRewrites): ?array
@@ -166,8 +168,8 @@ private function extractMostRelevantUrlRewrite(string $requestPath, array $urlRe
166168
* If request path matches the DB value or it's redirect - we can return result from DB
167169
* Otherwise return 301 redirect to request path from DB results
168170
*
169-
* @param string $requestPath
170-
* @param array $urlRewrite
171+
* @param string $requestPath
172+
* @param array $urlRewrite
171173
* @return array
172174
*/
173175
private function prepareUrlRewrite(string $requestPath, array $urlRewrite): array
@@ -197,7 +199,7 @@ private function prepareUrlRewrite(string $requestPath, array $urlRewrite): arra
197199
/**
198200
* Delete old URLs from DB.
199201
*
200-
* @param UrlRewrite[] $urls
202+
* @param UrlRewrite[] $urls
201203
* @return void
202204
*/
203205
private function deleteOldUrls(array $urls): void
@@ -242,7 +244,7 @@ private function deleteOldUrls(array $urls): void
242244
/**
243245
* Prepare array with unique entities
244246
*
245-
* @param UrlRewrite[] $urls
247+
* @param UrlRewrite[] $urls
246248
* @return array
247249
*/
248250
private function prepareUniqueEntities(array $urls): array
@@ -258,23 +260,33 @@ private function prepareUniqueEntities(array $urls): array
258260
}
259261
$uniqueEntities[$url->getStoreId()][$url->getEntityType()] = $entityIds;
260262
}
263+
261264
return $uniqueEntities;
262265
}
263266

264267
/**
265268
* @inheritDoc
266269
*/
267-
protected function doReplace(array $urls)
270+
protected function doReplace(array $urls): array
268271
{
269-
$this->deleteOldUrls($urls);
272+
$this->connection->beginTransaction();
270273

271-
$data = [];
272-
foreach ($urls as $url) {
273-
$data[] = $url->toArray();
274-
}
275274
try {
275+
$this->deleteOldUrls($urls);
276+
277+
$data = [];
278+
foreach ($urls as $url) {
279+
$data[] = $url->toArray();
280+
}
281+
276282
$this->insertMultiple($data);
283+
284+
$this->connection->commit();
285+
// @codingStandardsIgnoreStart
277286
} catch (\Magento\Framework\Exception\AlreadyExistsException $e) {
287+
// @codingStandardsIgnoreEnd
288+
$this->connection->rollBack();
289+
278290
/** @var \Magento\UrlRewrite\Service\V1\Data\UrlRewrite[] $urlConflicted */
279291
$urlConflicted = [];
280292
foreach ($urls as $url) {
@@ -298,6 +310,9 @@ protected function doReplace(array $urls)
298310
} else {
299311
throw $e->getPrevious() ?: $e;
300312
}
313+
} catch (\Exception $e) {
314+
$this->connection->rollBack();
315+
throw $e;
301316
}
302317

303318
return $urls;
@@ -306,12 +321,12 @@ protected function doReplace(array $urls)
306321
/**
307322
* Insert multiple
308323
*
309-
* @param array $data
324+
* @param array $data
310325
* @return void
311326
* @throws \Magento\Framework\Exception\AlreadyExistsException|\Exception
312327
* @throws \Exception
313328
*/
314-
protected function insertMultiple($data)
329+
protected function insertMultiple($data): void
315330
{
316331
try {
317332
$this->connection->insertMultiple($this->resource->getTableName(self::TABLE_NAME), $data);
@@ -331,11 +346,11 @@ protected function insertMultiple($data)
331346
/**
332347
* Get filter for url rows deletion due to provided urls
333348
*
334-
* @param UrlRewrite[] $urls
335-
* @return array
349+
* @param UrlRewrite[] $urls
350+
* @return array
336351
* @deprecated Not used anymore.
337352
*/
338-
protected function createFilterDataBasedOnUrls($urls)
353+
protected function createFilterDataBasedOnUrls($urls): array
339354
{
340355
$data = [];
341356
foreach ($urls as $url) {

dev/tests/integration/testsuite/Magento/Sales/_files/quote.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
$quote->collectTotals();
5757

5858
$quoteRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
59-
->create(\Magento\Quote\Api\CartRepositoryInterface::class);
59+
->get(\Magento\Quote\Api\CartRepositoryInterface::class);
6060
$quoteRepository->save($quote);
6161

6262
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */

lib/internal/Magento/Framework/Data/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public function getLastPageNumber()
259259
if (0 === $collectionSize) {
260260
return 1;
261261
} elseif ($this->_pageSize) {
262-
return ceil($collectionSize / $this->_pageSize);
262+
return (int)ceil($collectionSize / $this->_pageSize);
263263
} else {
264264
return 1;
265265
}

0 commit comments

Comments
 (0)