Skip to content

Commit 4b6cdb7

Browse files
authored
Merge pull request #6000 from magento-tsg-csl3/2.4-develop-pr36
[TSG-CSL3] For 2.4 (pr36)
2 parents 237c2b1 + d0b5f47 commit 4b6cdb7

File tree

46 files changed

+905
-141
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+905
-141
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Export.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Magento\Framework\App\Filesystem\DirectoryList;
1010

1111
/**
12+
* Class Export for exporting grid data as CSV file or MS Excel 2003 XML Document file
13+
*
1214
* @api
1315
* @deprecated 100.2.0 in favour of UI component implementation
1416
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -69,6 +71,8 @@ public function __construct(
6971
}
7072

7173
/**
74+
* Internal constructor, that is called from real constructor
75+
*
7276
* @return void
7377
* @throws \Magento\Framework\Exception\LocalizedException
7478
*/
@@ -242,6 +246,7 @@ protected function _getExportTotals()
242246

243247
/**
244248
* Iterate collection and call callback method per item
249+
*
245250
* For callback method first argument always is item object
246251
*
247252
* @param string $callback
@@ -273,7 +278,12 @@ public function _exportIterateCollection($callback, array $args)
273278

274279
$collection = $this->_getRowCollection($originalCollection);
275280
foreach ($collection as $item) {
276-
call_user_func_array([$this, $callback], array_merge([$item], $args));
281+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
282+
call_user_func_array(
283+
[$this, $callback],
284+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
285+
array_merge([$item], $args)
286+
);
277287
}
278288
}
279289
}
@@ -307,7 +317,7 @@ protected function _exportCsvItem(
307317
*/
308318
public function getCsvFile()
309319
{
310-
$name = md5(microtime());
320+
$name = hash('sha256', microtime());
311321
$file = $this->_path . '/' . $name . '.csv';
312322

313323
$this->_directory->create($this->_path);
@@ -432,11 +442,11 @@ public function getRowRecord(\Magento\Framework\DataObject $data)
432442
*/
433443
public function getExcelFile($sheetName = '')
434444
{
435-
$collection = $this->_getRowCollection();
445+
$collection = $this->_getPreparedCollection();
436446

437447
$convert = new \Magento\Framework\Convert\Excel($collection->getIterator(), [$this, 'getRowRecord']);
438448

439-
$name = md5(microtime());
449+
$name = hash('sha256', microtime());
440450
$file = $this->_path . '/' . $name . '.xml';
441451

442452
$this->_directory->create($this->_path);
@@ -551,6 +561,8 @@ public function _getPreparedCollection()
551561
}
552562

553563
/**
564+
* Get export page size
565+
*
554566
* @return int
555567
*/
556568
public function getExportPageSize()

app/code/Magento/Backend/Block/Widget/Grid/Extended.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Magento\Framework\App\Filesystem\DirectoryList;
99

1010
/**
11+
* Extended Grid Widget
12+
*
1113
* @api
1214
* @deprecated 100.2.0 in favour of UI component implementation
1315
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
@@ -177,7 +179,10 @@ class Extended extends \Magento\Backend\Block\Widget\Grid implements \Magento\Ba
177179
protected $_path = 'export';
178180

179181
/**
182+
* Initialization
183+
*
180184
* @return void
185+
* @throws \Magento\Framework\Exception\FileSystemException
181186
*/
182187
protected function _construct()
183188
{
@@ -297,6 +302,7 @@ public function addColumn($columnId, $column)
297302
);
298303
$this->getColumnSet()->getChildBlock($columnId)->setGrid($this);
299304
} else {
305+
// phpcs:ignore Magento2.Exceptions.DirectThrow
300306
throw new \Exception(__('Please correct the column format and try again.'));
301307
}
302308

@@ -471,10 +477,6 @@ protected function _prepareMassactionColumn()
471477
protected function _prepareCollection()
472478
{
473479
if ($this->getCollection()) {
474-
if ($this->getCollection()->isLoaded()) {
475-
$this->getCollection()->clear();
476-
}
477-
478480
parent::_prepareCollection();
479481

480482
if (!$this->_isExport) {
@@ -663,6 +665,7 @@ public function setEmptyCellLabel($label)
663665
*/
664666
public function getRowUrl($item)
665667
{
668+
// phpstan:ignore "Call to an undefined static method"
666669
$res = parent::getRowUrl($item);
667670
return $res ? $res : '#';
668671
}
@@ -680,6 +683,7 @@ public function getMultipleRows($item)
680683

681684
/**
682685
* Retrieve columns for multiple rows
686+
*
683687
* @return array
684688
*/
685689
public function getMultipleRowColumns()
@@ -943,6 +947,7 @@ protected function _getExportTotals()
943947

944948
/**
945949
* Iterate collection and call callback method per item
950+
*
946951
* For callback method first argument always is item object
947952
*
948953
* @param string $callback
@@ -972,7 +977,12 @@ public function _exportIterateCollection($callback, array $args)
972977
$page++;
973978

974979
foreach ($collection as $item) {
975-
call_user_func_array([$this, $callback], array_merge([$item], $args));
980+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
981+
call_user_func_array(
982+
[$this, $callback],
983+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
984+
array_merge([$item], $args)
985+
);
976986
}
977987
}
978988
}
@@ -1009,6 +1019,7 @@ public function getCsvFile()
10091019
$this->_isExport = true;
10101020
$this->_prepareGrid();
10111021

1022+
// phpcs:ignore Magento2.Security.InsecureFunction
10121023
$name = md5(microtime());
10131024
$file = $this->_path . '/' . $name . '.csv';
10141025

@@ -1153,6 +1164,7 @@ public function getExcelFile($sheetName = '')
11531164
[$this, 'getRowRecord']
11541165
);
11551166

1167+
// phpcs:ignore Magento2.Security.InsecureFunction
11561168
$name = md5(microtime());
11571169
$file = $this->_path . '/' . $name . '.xml';
11581170

@@ -1244,7 +1256,7 @@ public function setCollection($collection)
12441256
}
12451257

12461258
/**
1247-
* get collection object
1259+
* Get collection object
12481260
*
12491261
* @return \Magento\Framework\Data\Collection
12501262
*/

app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/ExtendedTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public function testPrepareLoadedCollection()
4141
$layout->expects($this->any())->method('getBlock')->willReturn($columnSet);
4242

4343
$collection = $this->createMock(Collection::class);
44-
$collection->expects($this->atLeastOnce())->method('isLoaded')->willReturn(true);
45-
$collection->expects($this->atLeastOnce())->method('clear');
44+
$collection->expects($this->never())->method('isLoaded');
45+
$collection->expects($this->never())->method('clear');
4646
$collection->expects($this->atLeastOnce())->method('load');
4747

4848
/** @var Extended $block */

app/code/Magento/CatalogInventory/etc/webapi.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@
1010
<route url="/V1/stockItems/:productSku" method="GET">
1111
<service class="Magento\CatalogInventory\Api\StockRegistryInterface" method="getStockItemBySku"/>
1212
<resources>
13-
<resource ref="Magento_CatalogInventory::cataloginventory"/>
13+
<resource ref="Magento_Catalog::catalog_inventory"/>
1414
</resources>
1515
</route>
1616
<route url="/V1/products/:productSku/stockItems/:itemId" method="PUT">
1717
<service class="Magento\CatalogInventory\Api\StockRegistryInterface" method="updateStockItemBySku"/>
1818
<resources>
19-
<resource ref="Magento_CatalogInventory::cataloginventory"/>
19+
<resource ref="Magento_Catalog::catalog_inventory"/>
2020
</resources>
2121
</route>
2222
<route url="/V1/stockItems/lowStock/" method="GET">
2323
<service class="Magento\CatalogInventory\Api\StockRegistryInterface" method="getLowStockItems"/>
2424
<resources>
25-
<resource ref="Magento_CatalogInventory::cataloginventory"/>
25+
<resource ref="Magento_Catalog::catalog_inventory"/>
2626
</resources>
2727
</route>
2828
<route url="/V1/stockStatuses/:productSku" method="GET">
2929
<service class="Magento\CatalogInventory\Api\StockRegistryInterface" method="getStockStatusBySku"/>
3030
<resources>
31-
<resource ref="Magento_CatalogInventory::cataloginventory"/>
31+
<resource ref="Magento_Catalog::catalog_inventory"/>
3232
</resources>
3333
</route>
3434
</routes>

app/code/Magento/Checkout/view/frontend/web/js/region-updater.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ define([
5656
if (this.options.isMultipleCountriesAllowed) {
5757
this.element.parents('div.field').show();
5858
this.element.on('change', $.proxy(function (e) {
59+
// clear region inputs on country change
60+
$(this.options.regionListId).val('');
61+
$(this.options.regionInputId).val('');
5962
this._updateRegion($(e.target).val());
6063
}, this));
6164

@@ -165,9 +168,6 @@ define([
165168
this._clearError();
166169
this._checkRegionRequired(country);
167170

168-
$(regionList).find('option:selected').removeAttr('selected');
169-
regionInput.val('');
170-
171171
// Populate state/province dropdown list if available or use input box
172172
if (this.options.regionJson[country]) {
173173
this._removeSelectOptions(regionList);

app/code/Magento/Checkout/view/frontend/web/template/minicart/item/default.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444
<!-- ko if: Array.isArray(option.value) -->
4545
<span data-bind="html: option.value.join('<br>')"></span>
4646
<!-- /ko -->
47-
<!-- ko if: (!Array.isArray(option.value) && option.option_type == 'file') -->
47+
<!-- ko if: (!Array.isArray(option.value) && ['file', 'html'].includes(option.option_type)) -->
4848
<span data-bind="html: option.value"></span>
4949
<!-- /ko -->
50-
<!-- ko if: (!Array.isArray(option.value) && option.option_type != 'file') -->
51-
<span data-bind="text: option.value"></span>
50+
<!-- ko if: (!Array.isArray(option.value) && !['file', 'html'].includes(option.option_type)) -->
51+
<span data-bind="text: option.value"></span>
5252
<!-- /ko -->
5353
</dd>
5454
<!-- /ko -->

app/code/Magento/Customer/view/frontend/web/js/customer-data.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,6 @@ define([
3030
url.setBaseUrl(window.BASE_URL);
3131
options.sectionLoadUrl = url.build('customer/section/load');
3232

33-
//TODO: remove global change, in this case made for initNamespaceStorage
34-
$.cookieStorage.setConf({
35-
path: '/',
36-
expires: 1
37-
});
38-
39-
storage = $.initNamespaceStorage('mage-cache-storage').localStorage;
40-
storageInvalidation = $.initNamespaceStorage('mage-cache-storage-section-invalidation').localStorage;
41-
4233
/**
4334
* @param {Object} invalidateOptions
4435
*/
@@ -222,6 +213,18 @@ define([
222213
}
223214
},
224215

216+
/**
217+
* Storage init
218+
*/
219+
initStorage: function () {
220+
$.cookieStorage.setConf({
221+
path: '/',
222+
expires: new Date(Date.now() + parseInt(options.cookieLifeTime, 10) * 1000)
223+
});
224+
storage = $.initNamespaceStorage('mage-cache-storage').localStorage;
225+
storageInvalidation = $.initNamespaceStorage('mage-cache-storage-section-invalidation').localStorage;
226+
},
227+
225228
/**
226229
* Retrieve the list of sections that has expired since last page reload.
227230
*
@@ -357,6 +360,7 @@ define([
357360
*/
358361
'Magento_Customer/js/customer-data': function (settings) {
359362
options = settings;
363+
customerData.initStorage();
360364
invalidateCacheBySessionTimeOut(settings);
361365
invalidateCacheByCloseCookieSession();
362366
customerData.init();

app/code/Magento/Persistent/Observer/SynchronizePersistentOnLoginObserver.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
/**
1313
* Persistent Session Observer
14+
*
15+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
16+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1417
*/
1518
class SynchronizePersistentOnLoginObserver implements ObserverInterface
1619
{
@@ -63,6 +66,8 @@ public function __construct(
6366
}
6467

6568
/**
69+
* Synchronize persistent session data with logged in customer
70+
*
6671
* @param Observer $observer
6772
* @return void
6873
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
@@ -96,8 +101,9 @@ public function execute(Observer $observer)
96101
if (!$sessionModel->getId()) {
97102
/** @var \Magento\Persistent\Model\Session $sessionModel */
98103
$sessionModel = $this->_sessionFactory->create();
99-
$sessionModel->setCustomerId($customer->getId())->save();
104+
$sessionModel->setCustomerId($customer->getId());
100105
}
106+
$sessionModel->save();
101107
$this->_persistentSession->setSession($sessionModel);
102108
}
103109

app/code/Magento/Sales/Model/Order/Pdf/Creditmemo.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class Creditmemo extends AbstractPdf
2020
*/
2121
protected $_storeManager;
2222

23+
/**
24+
* @var \Magento\Store\Model\App\Emulation
25+
*/
26+
private $appEmulation;
27+
2328
/**
2429
* @param \Magento\Payment\Helper\Data $paymentData
2530
* @param \Magento\Framework\Stdlib\StringUtils $string
@@ -32,7 +37,7 @@ class Creditmemo extends AbstractPdf
3237
* @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
3338
* @param \Magento\Sales\Model\Order\Address\Renderer $addressRenderer
3439
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
35-
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
40+
* @param \Magento\Store\Model\App\Emulation|null $appEmulation
3641
* @param array $data
3742
*
3843
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -50,11 +55,11 @@ public function __construct(
5055
\Magento\Framework\Translate\Inline\StateInterface $inlineTranslation,
5156
\Magento\Sales\Model\Order\Address\Renderer $addressRenderer,
5257
\Magento\Store\Model\StoreManagerInterface $storeManager,
53-
\Magento\Framework\Locale\ResolverInterface $localeResolver,
58+
\Magento\Store\Model\App\Emulation $appEmulation,
5459
array $data = []
5560
) {
5661
$this->_storeManager = $storeManager;
57-
$this->_localeResolver = $localeResolver;
62+
$this->appEmulation = $appEmulation;
5863
parent::__construct(
5964
$paymentData,
6065
$string,
@@ -150,7 +155,11 @@ public function getPdf($creditmemos = [])
150155

151156
foreach ($creditmemos as $creditmemo) {
152157
if ($creditmemo->getStoreId()) {
153-
$this->_localeResolver->emulate($creditmemo->getStoreId());
158+
$this->appEmulation->startEnvironmentEmulation(
159+
$creditmemo->getStoreId(),
160+
\Magento\Framework\App\Area::AREA_FRONTEND,
161+
true
162+
);
154163
$this->_storeManager->setCurrentStore($creditmemo->getStoreId());
155164
}
156165
$page = $this->newPage();
@@ -185,7 +194,7 @@ public function getPdf($creditmemos = [])
185194
/* Add totals */
186195
$this->insertTotals($page, $creditmemo);
187196
if ($creditmemo->getStoreId()) {
188-
$this->_localeResolver->revert();
197+
$this->appEmulation->stopEnvironmentEmulation();
189198
}
190199
}
191200
$this->_afterGetPdf();

0 commit comments

Comments
 (0)