Skip to content

Commit

Permalink
Merge branch '2.4-develop' into 2.4-develop-temporary-three-prs
Browse files Browse the repository at this point in the history
  • Loading branch information
lenaorobei authored Jan 24, 2020
2 parents 5014fee + 29cb41d commit 4ca5ecf
Show file tree
Hide file tree
Showing 144 changed files with 4,838 additions and 853 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/Block/Media/Uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function _construct()

$this->setId($this->getId() . '_Uploader');

$uploadUrl = $this->_urlBuilder->addSessionParam()->getUrl('adminhtml/*/upload');
$uploadUrl = $this->_urlBuilder->getUrl('adminhtml/*/upload');
$this->getConfig()->setUrl($uploadUrl);
$this->getConfig()->setParams(['form_key' => $this->getFormKey()]);
$this->getConfig()->setFileField('file');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected function _prepareLayout()
);

$this->getUploader()->getConfig()->setUrl(
$this->_urlBuilder->addSessionParam()->getUrl('catalog/product_gallery/upload')
$this->_urlBuilder->getUrl('catalog/product_gallery/upload')
)->setFileField(
'image'
)->setFilters(
Expand Down
13 changes: 2 additions & 11 deletions app/code/Magento/Catalog/Controller/Product/Compare/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Magento\Framework\View\Result\PageFactory;

/**
* View products compare in frontend
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Index extends \Magento\Catalog\Controller\Product\Compare implements HttpGetActionInterface
Expand Down Expand Up @@ -74,23 +76,12 @@ public function __construct(
*/
public function execute()
{
$items = $this->getRequest()->getParam('items');

$beforeUrl = $this->getRequest()->getParam(self::PARAM_NAME_URL_ENCODED);
if ($beforeUrl) {
$this->_catalogSession->setBeforeCompareUrl(
$this->urlDecoder->decode($beforeUrl)
);
}

if ($items) {
$items = explode(',', $items);
/** @var \Magento\Catalog\Model\Product\Compare\ListCompare $list */
$list = $this->_catalogProductCompareList;
$list->addProducts($items);
$resultRedirect = $this->resultRedirectFactory->create();
return $resultRedirect->setPath('*/*/*');
}
return $this->resultPageFactory->create();
}
}
8 changes: 1 addition & 7 deletions app/code/Magento/Catalog/Helper/Product/Compare.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @api
* @SuppressWarnings(PHPMD.LongVariable)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
* @since 100.0.2
*/
class Compare extends \Magento\Framework\Url\Helper\Data
Expand Down Expand Up @@ -145,16 +146,9 @@ public function __construct(
*/
public function getListUrl()
{
$itemIds = [];
foreach ($this->getItemCollection() as $item) {
$itemIds[] = $item->getId();
}

$params = [
'items' => implode(',', $itemIds),
\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED => $this->getEncodedUrl()
];

return $this->_getUrl('catalog/product_compare', $params);
}

Expand Down
5 changes: 0 additions & 5 deletions app/code/Magento/Catalog/Model/Product/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,10 @@ public function getUrlInStore(\Magento\Catalog\Model\Product $product, $params =
*/
public function getProductUrl($product, $useSid = null)
{
if ($useSid === null) {
$useSid = $this->sidResolver->getUseSessionInUrl();
}

$params = [];
if (!$useSid) {
$params['_nosid'] = true;
}

return $this->getUrl($product, $params);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ public function testExecute()
->method('getParam')
->willReturnMap(
[
['items', null, null],
['uenc', null, $beforeUrl],
]
);
Expand All @@ -141,34 +140,7 @@ public function testExecute()
->method('setBeforeCompareUrl')
->with($beforeUrl . '1')
->willReturnSelf();
$this->listCompareMock->expects($this->never())->method('addProducts');
$this->redirectFactoryMock->expects($this->never())->method('create');
$this->index->execute();
}

public function testExecuteWithItems()
{
$this->request->expects($this->any())
->method('getParam')
->willReturnMap(
[
['items', null, '1,2,3'],
['uenc', null, null],
]
);
$this->decoderMock->expects($this->never())->method('decode');
$this->catalogSession->expects($this->never())->method('setBeforeCompareUrl');

$this->listCompareMock->expects($this->once())
->method('addProducts')
->with([1, 2, 3]);
$redirect = $this->createPartialMock(\Magento\Framework\Controller\Result\Redirect::class, ['setPath']);
$redirect->expects($this->once())
->method('setPath')
->with('*/*/*');
$this->redirectFactoryMock->expects($this->once())
->method('create')
->willReturn($redirect);
$this->index->execute();
}
}
7 changes: 3 additions & 4 deletions app/code/Magento/Catalog/Test/Unit/Model/Product/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,11 @@ public function testGetUrl(
$this->assertEquals($requestPathProduct, $this->model->getUrlInStore($product, $routeParams));
break;
case 'getProductUrl':
$this->assertEquals($requestPathProduct, $this->model->getProductUrl($product, true));
$this->assertEquals($requestPathProduct, $this->model->getProductUrl($product, null));
$this->sidResolver
->expects($this->once())
->expects($this->never())
->method('getUseSessionInUrl')
->will($this->returnValue(true));
$this->assertEquals($requestPathProduct, $this->model->getProductUrl($product, null));
break;
}
}
Expand Down Expand Up @@ -212,7 +211,7 @@ public function getUrlDataProvider()
1,
1,
[],
['_direct' => '/product/url/path', '_query' => []],
['_direct' => '/product/url/path', '_query' => [], '_nosid' => true],
null,
null,
]
Expand Down
28 changes: 17 additions & 11 deletions app/code/Magento/CatalogImportExport/Model/Export/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
*/
namespace Magento\CatalogImportExport\Model\Export;

use Magento\Catalog\Model\Product as ProductEntity;
use Magento\Catalog\Model\ResourceModel\Product\Option\Collection;
use Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
use Magento\CatalogImportExport\Model\Import\Product\CategoryProcessor;
use Magento\Framework\App\ObjectManager;
use Magento\ImportExport\Model\Import;
use \Magento\Store\Model\Store;
use \Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
use Magento\Catalog\Model\Product as ProductEntity;
use Magento\Store\Model\Store;

/**
* Export entity product model
Expand All @@ -21,6 +22,8 @@
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
* @SuppressWarnings(PHPMD.ExcessiveClassLength)
* @SuppressWarnings(PHPMD.TooManyMethods)
* @since 100.0.2
*/
class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
Expand Down Expand Up @@ -348,6 +351,10 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
* @var string
*/
private $productEntityLinkField;
/**
* @var ProductFilterInterface
*/
private $filter;

/**
* Product constructor.
Expand All @@ -369,6 +376,7 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
* @param ProductEntity\LinkTypeProvider $linkTypeProvider
* @param RowCustomizerInterface $rowCustomizer
* @param array $dateAttrCodes
* @param ProductFilterInterface $filter
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function __construct(
Expand All @@ -388,7 +396,8 @@ public function __construct(
\Magento\CatalogImportExport\Model\Export\Product\Type\Factory $_typeFactory,
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider,
\Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer,
array $dateAttrCodes = []
array $dateAttrCodes = [],
?ProductFilterInterface $filter = null
) {
$this->_entityCollectionFactory = $collectionFactory;
$this->_exportConfig = $exportConfig;
Expand All @@ -404,6 +413,7 @@ public function __construct(
$this->_linkTypeProvider = $linkTypeProvider;
$this->rowCustomizer = $rowCustomizer;
$this->dateAttrCodes = array_merge($this->dateAttrCodes, $dateAttrCodes);
$this->filter = $filter ?? ObjectManager::getInstance()->get(ProductFilterInterface::class);

parent::__construct($localeDate, $config, $resource, $storeManager);

Expand Down Expand Up @@ -819,9 +829,11 @@ protected function getItemsPerPage()
case 'g':
$memoryLimit *= 1024;
// fall-through intentional
// no break
case 'm':
$memoryLimit *= 1024;
// fall-through intentional
// no break
case 'k':
$memoryLimit *= 1024;
break;
Expand Down Expand Up @@ -913,12 +925,7 @@ protected function _prepareEntityCollection(\Magento\Eav\Model\Entity\Collection
$exportFilter = !empty($this->_parameters[\Magento\ImportExport\Model\Export::FILTER_ELEMENT_GROUP]) ?
$this->_parameters[\Magento\ImportExport\Model\Export::FILTER_ELEMENT_GROUP] : [];

if (isset($exportFilter['category_ids'])
&& trim($exportFilter['category_ids'])
&& $collection instanceof \Magento\Catalog\Model\ResourceModel\Product\Collection
) {
$collection->addCategoriesFilter(['in' => explode(',', $exportFilter['category_ids'])]);
}
$collection = $this->filter->filter($collection, $exportFilter);

return parent::_prepareEntityCollection($collection);
}
Expand Down Expand Up @@ -979,7 +986,6 @@ protected function loadCollection(): array
$collection = $this->_getEntityCollection();
foreach (array_keys($this->_storeIdToCode) as $storeId) {
$collection->setOrder('entity_id', 'asc');
$this->_prepareEntityCollection($collection);
$collection->setStoreId($storeId);
$collection->load();
foreach ($collection as $itemId => $item) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogImportExport\Model\Export\Product;

use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\CatalogImportExport\Model\Export\ProductFilterInterface;

/**
* Category filter for products export
*/
class CategoryFilter implements ProductFilterInterface
{
private const NAME = 'category_ids';

/**
* @inheritDoc
*/
public function filter(Collection $collection, array $filters): Collection
{
$value = trim($filters[self::NAME] ?? '');
if ($value) {
$collection->addCategoriesFilter(['in' => explode(',', $value)]);
}
return $collection;
}
}
111 changes: 111 additions & 0 deletions app/code/Magento/CatalogImportExport/Model/Export/Product/Stock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogImportExport\Model\Export\Product;

use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\CatalogInventory\Model\Configuration;
use Magento\CatalogInventory\Model\ResourceModel\Stock\Item as StockItemResourceModel;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;

/**
* Stock status collection filter
*/
class Stock
{
/**
* @var ScopeConfigInterface
*/
private $scopeConfig;
/**
* @var StockItemResourceModel
*/
private $stockItemResourceModel;

/**
* @param ScopeConfigInterface $scopeConfig
* @param StockItemResourceModel $stockItemResourceModel
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
StockItemResourceModel $stockItemResourceModel
) {
$this->scopeConfig = $scopeConfig;
$this->stockItemResourceModel = $stockItemResourceModel;
}

/**
* Filter provided collection to return only "in stock" products
*
* @param Collection $collection
* @return Collection
*/
public function addInStockFilterToCollection(Collection $collection): Collection
{
$manageStock = $this->scopeConfig->getValue(
Configuration::XML_PATH_MANAGE_STOCK,
ScopeInterface::SCOPE_STORE
);
$cond = [
'{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=1 AND {{table}}.is_in_stock=1',
'{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=0'
];

if ($manageStock) {
$cond[] = '{{table}}.use_config_manage_stock = 1 AND {{table}}.is_in_stock=1';
} else {
$cond[] = '{{table}}.use_config_manage_stock = 1';
}
return $this->addFilterToCollection($collection, '(' . join(') OR (', $cond) . ')');
}

/**
* Filter provided collection to return only "out of stock" products
*
* @param Collection $collection
* @return Collection
*/
public function addOutOfStockFilterToCollection(Collection $collection): Collection
{
$manageStock = $this->scopeConfig->getValue(
Configuration::XML_PATH_MANAGE_STOCK,
ScopeInterface::SCOPE_STORE
);
$cond = [
'{{table}}.use_config_manage_stock = 0 AND {{table}}.manage_stock=1 AND {{table}}.is_in_stock=0',
];

if ($manageStock) {
$cond[] = '{{table}}.use_config_manage_stock = 1 AND {{table}}.is_in_stock=0';
}
return $this->addFilterToCollection($collection, '(' . join(') OR (', $cond) . ')');
}

/**
* Add stock status filter to the collection
*
* @param Collection $collection
* @param string $condition
* @return Collection
*/
private function addFilterToCollection(Collection $collection, string $condition): Collection
{
$condition = str_replace(
'{{table}}',
'inventory_stock_item_filter',
'({{table}}.product_id=e.entity_id) AND (' . $condition . ')'
);
$collection->getSelect()
->joinInner(
['inventory_stock_item_filter' => $this->stockItemResourceModel->getMainTable()],
$condition,
[]
);
return $collection;
}
}
Loading

0 comments on commit 4ca5ecf

Please sign in to comment.