Skip to content

Commit

Permalink
Merge pull request #6000 from magento-tsg-csl3/2.4-develop-pr36
Browse files Browse the repository at this point in the history
[TSG-CSL3] For 2.4 (pr36)
  • Loading branch information
zakdma authored Aug 10, 2020
2 parents 237c2b1 + d0b5f47 commit 4b6cdb7
Show file tree
Hide file tree
Showing 46 changed files with 905 additions and 141 deletions.
20 changes: 16 additions & 4 deletions app/code/Magento/Backend/Block/Widget/Grid/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Magento\Framework\App\Filesystem\DirectoryList;

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

/**
* Internal constructor, that is called from real constructor
*
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
*/
Expand Down Expand Up @@ -242,6 +246,7 @@ protected function _getExportTotals()

/**
* Iterate collection and call callback method per item
*
* For callback method first argument always is item object
*
* @param string $callback
Expand Down Expand Up @@ -273,7 +278,12 @@ public function _exportIterateCollection($callback, array $args)

$collection = $this->_getRowCollection($originalCollection);
foreach ($collection as $item) {
call_user_func_array([$this, $callback], array_merge([$item], $args));
//phpcs:ignore Magento2.Functions.DiscouragedFunction
call_user_func_array(
[$this, $callback],
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
array_merge([$item], $args)
);
}
}
}
Expand Down Expand Up @@ -307,7 +317,7 @@ protected function _exportCsvItem(
*/
public function getCsvFile()
{
$name = md5(microtime());
$name = hash('sha256', microtime());
$file = $this->_path . '/' . $name . '.csv';

$this->_directory->create($this->_path);
Expand Down Expand Up @@ -432,11 +442,11 @@ public function getRowRecord(\Magento\Framework\DataObject $data)
*/
public function getExcelFile($sheetName = '')
{
$collection = $this->_getRowCollection();
$collection = $this->_getPreparedCollection();

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

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

$this->_directory->create($this->_path);
Expand Down Expand Up @@ -551,6 +561,8 @@ public function _getPreparedCollection()
}

/**
* Get export page size
*
* @return int
*/
public function getExportPageSize()
Expand Down
24 changes: 18 additions & 6 deletions app/code/Magento/Backend/Block/Widget/Grid/Extended.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Magento\Framework\App\Filesystem\DirectoryList;

/**
* Extended Grid Widget
*
* @api
* @deprecated 100.2.0 in favour of UI component implementation
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
Expand Down Expand Up @@ -177,7 +179,10 @@ class Extended extends \Magento\Backend\Block\Widget\Grid implements \Magento\Ba
protected $_path = 'export';

/**
* Initialization
*
* @return void
* @throws \Magento\Framework\Exception\FileSystemException
*/
protected function _construct()
{
Expand Down Expand Up @@ -297,6 +302,7 @@ public function addColumn($columnId, $column)
);
$this->getColumnSet()->getChildBlock($columnId)->setGrid($this);
} else {
// phpcs:ignore Magento2.Exceptions.DirectThrow
throw new \Exception(__('Please correct the column format and try again.'));
}

Expand Down Expand Up @@ -471,10 +477,6 @@ protected function _prepareMassactionColumn()
protected function _prepareCollection()
{
if ($this->getCollection()) {
if ($this->getCollection()->isLoaded()) {
$this->getCollection()->clear();
}

parent::_prepareCollection();

if (!$this->_isExport) {
Expand Down Expand Up @@ -663,6 +665,7 @@ public function setEmptyCellLabel($label)
*/
public function getRowUrl($item)
{
// phpstan:ignore "Call to an undefined static method"
$res = parent::getRowUrl($item);
return $res ? $res : '#';
}
Expand All @@ -680,6 +683,7 @@ public function getMultipleRows($item)

/**
* Retrieve columns for multiple rows
*
* @return array
*/
public function getMultipleRowColumns()
Expand Down Expand Up @@ -943,6 +947,7 @@ protected function _getExportTotals()

/**
* Iterate collection and call callback method per item
*
* For callback method first argument always is item object
*
* @param string $callback
Expand Down Expand Up @@ -972,7 +977,12 @@ public function _exportIterateCollection($callback, array $args)
$page++;

foreach ($collection as $item) {
call_user_func_array([$this, $callback], array_merge([$item], $args));
//phpcs:ignore Magento2.Functions.DiscouragedFunction
call_user_func_array(
[$this, $callback],
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
array_merge([$item], $args)
);
}
}
}
Expand Down Expand Up @@ -1009,6 +1019,7 @@ public function getCsvFile()
$this->_isExport = true;
$this->_prepareGrid();

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

Expand Down Expand Up @@ -1153,6 +1164,7 @@ public function getExcelFile($sheetName = '')
[$this, 'getRowRecord']
);

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

Expand Down Expand Up @@ -1244,7 +1256,7 @@ public function setCollection($collection)
}

/**
* get collection object
* Get collection object
*
* @return \Magento\Framework\Data\Collection
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function testPrepareLoadedCollection()
$layout->expects($this->any())->method('getBlock')->willReturn($columnSet);

$collection = $this->createMock(Collection::class);
$collection->expects($this->atLeastOnce())->method('isLoaded')->willReturn(true);
$collection->expects($this->atLeastOnce())->method('clear');
$collection->expects($this->never())->method('isLoaded');
$collection->expects($this->never())->method('clear');
$collection->expects($this->atLeastOnce())->method('load');

/** @var Extended $block */
Expand Down
8 changes: 4 additions & 4 deletions app/code/Magento/CatalogInventory/etc/webapi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@
<route url="/V1/stockItems/:productSku" method="GET">
<service class="Magento\CatalogInventory\Api\StockRegistryInterface" method="getStockItemBySku"/>
<resources>
<resource ref="Magento_CatalogInventory::cataloginventory"/>
<resource ref="Magento_Catalog::catalog_inventory"/>
</resources>
</route>
<route url="/V1/products/:productSku/stockItems/:itemId" method="PUT">
<service class="Magento\CatalogInventory\Api\StockRegistryInterface" method="updateStockItemBySku"/>
<resources>
<resource ref="Magento_CatalogInventory::cataloginventory"/>
<resource ref="Magento_Catalog::catalog_inventory"/>
</resources>
</route>
<route url="/V1/stockItems/lowStock/" method="GET">
<service class="Magento\CatalogInventory\Api\StockRegistryInterface" method="getLowStockItems"/>
<resources>
<resource ref="Magento_CatalogInventory::cataloginventory"/>
<resource ref="Magento_Catalog::catalog_inventory"/>
</resources>
</route>
<route url="/V1/stockStatuses/:productSku" method="GET">
<service class="Magento\CatalogInventory\Api\StockRegistryInterface" method="getStockStatusBySku"/>
<resources>
<resource ref="Magento_CatalogInventory::cataloginventory"/>
<resource ref="Magento_Catalog::catalog_inventory"/>
</resources>
</route>
</routes>
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ define([
if (this.options.isMultipleCountriesAllowed) {
this.element.parents('div.field').show();
this.element.on('change', $.proxy(function (e) {
// clear region inputs on country change
$(this.options.regionListId).val('');
$(this.options.regionInputId).val('');
this._updateRegion($(e.target).val());
}, this));

Expand Down Expand Up @@ -165,9 +168,6 @@ define([
this._clearError();
this._checkRegionRequired(country);

$(regionList).find('option:selected').removeAttr('selected');
regionInput.val('');

// Populate state/province dropdown list if available or use input box
if (this.options.regionJson[country]) {
this._removeSelectOptions(regionList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
<!-- ko if: Array.isArray(option.value) -->
<span data-bind="html: option.value.join('<br>')"></span>
<!-- /ko -->
<!-- ko if: (!Array.isArray(option.value) && option.option_type == 'file') -->
<!-- ko if: (!Array.isArray(option.value) && ['file', 'html'].includes(option.option_type)) -->
<span data-bind="html: option.value"></span>
<!-- /ko -->
<!-- ko if: (!Array.isArray(option.value) && option.option_type != 'file') -->
<span data-bind="text: option.value"></span>
<!-- ko if: (!Array.isArray(option.value) && !['file', 'html'].includes(option.option_type)) -->
<span data-bind="text: option.value"></span>
<!-- /ko -->
</dd>
<!-- /ko -->
Expand Down
22 changes: 13 additions & 9 deletions app/code/Magento/Customer/view/frontend/web/js/customer-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ define([
url.setBaseUrl(window.BASE_URL);
options.sectionLoadUrl = url.build('customer/section/load');

//TODO: remove global change, in this case made for initNamespaceStorage
$.cookieStorage.setConf({
path: '/',
expires: 1
});

storage = $.initNamespaceStorage('mage-cache-storage').localStorage;
storageInvalidation = $.initNamespaceStorage('mage-cache-storage-section-invalidation').localStorage;

/**
* @param {Object} invalidateOptions
*/
Expand Down Expand Up @@ -222,6 +213,18 @@ define([
}
},

/**
* Storage init
*/
initStorage: function () {
$.cookieStorage.setConf({
path: '/',
expires: new Date(Date.now() + parseInt(options.cookieLifeTime, 10) * 1000)
});
storage = $.initNamespaceStorage('mage-cache-storage').localStorage;
storageInvalidation = $.initNamespaceStorage('mage-cache-storage-section-invalidation').localStorage;
},

/**
* Retrieve the list of sections that has expired since last page reload.
*
Expand Down Expand Up @@ -357,6 +360,7 @@ define([
*/
'Magento_Customer/js/customer-data': function (settings) {
options = settings;
customerData.initStorage();
invalidateCacheBySessionTimeOut(settings);
invalidateCacheByCloseCookieSession();
customerData.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

/**
* Persistent Session Observer
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class SynchronizePersistentOnLoginObserver implements ObserverInterface
{
Expand Down Expand Up @@ -63,6 +66,8 @@ public function __construct(
}

/**
* Synchronize persistent session data with logged in customer
*
* @param Observer $observer
* @return void
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
Expand Down Expand Up @@ -96,8 +101,9 @@ public function execute(Observer $observer)
if (!$sessionModel->getId()) {
/** @var \Magento\Persistent\Model\Session $sessionModel */
$sessionModel = $this->_sessionFactory->create();
$sessionModel->setCustomerId($customer->getId())->save();
$sessionModel->setCustomerId($customer->getId());
}
$sessionModel->save();
$this->_persistentSession->setSession($sessionModel);
}

Expand Down
19 changes: 14 additions & 5 deletions app/code/Magento/Sales/Model/Order/Pdf/Creditmemo.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class Creditmemo extends AbstractPdf
*/
protected $_storeManager;

/**
* @var \Magento\Store\Model\App\Emulation
*/
private $appEmulation;

/**
* @param \Magento\Payment\Helper\Data $paymentData
* @param \Magento\Framework\Stdlib\StringUtils $string
Expand All @@ -32,7 +37,7 @@ class Creditmemo extends AbstractPdf
* @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
* @param \Magento\Sales\Model\Order\Address\Renderer $addressRenderer
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
* @param \Magento\Store\Model\App\Emulation|null $appEmulation
* @param array $data
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
Expand All @@ -50,11 +55,11 @@ public function __construct(
\Magento\Framework\Translate\Inline\StateInterface $inlineTranslation,
\Magento\Sales\Model\Order\Address\Renderer $addressRenderer,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\Locale\ResolverInterface $localeResolver,
\Magento\Store\Model\App\Emulation $appEmulation,
array $data = []
) {
$this->_storeManager = $storeManager;
$this->_localeResolver = $localeResolver;
$this->appEmulation = $appEmulation;
parent::__construct(
$paymentData,
$string,
Expand Down Expand Up @@ -150,7 +155,11 @@ public function getPdf($creditmemos = [])

foreach ($creditmemos as $creditmemo) {
if ($creditmemo->getStoreId()) {
$this->_localeResolver->emulate($creditmemo->getStoreId());
$this->appEmulation->startEnvironmentEmulation(
$creditmemo->getStoreId(),
\Magento\Framework\App\Area::AREA_FRONTEND,
true
);
$this->_storeManager->setCurrentStore($creditmemo->getStoreId());
}
$page = $this->newPage();
Expand Down Expand Up @@ -185,7 +194,7 @@ public function getPdf($creditmemos = [])
/* Add totals */
$this->insertTotals($page, $creditmemo);
if ($creditmemo->getStoreId()) {
$this->_localeResolver->revert();
$this->appEmulation->stopEnvironmentEmulation();
}
}
$this->_afterGetPdf();
Expand Down
Loading

0 comments on commit 4b6cdb7

Please sign in to comment.