-
Notifications
You must be signed in to change notification settings - Fork 9.4k
[Backport] MAGETWO-61422 Respect Category Top Navigation Max Depth setting #22235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cfdeeba
Respect Category Top Navigation Max Depth setting
arnoudhgz 8dcd59b
Add scope config in backwards-compatible way
mzeis f5c21b3
Fix static code test
mzeis 9f424aa
magento/magento2#22235: Flat catalog fix.
p-bystritsky 1847826
Merge remote-tracking branch 'mainline/2.2-develop' into 2.2-develop-…
p-bystritsky 6f56333
magento/magento2#22235: Static test fix.
p-bystritsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,15 @@ | |
namespace Magento\Catalog\Model\ResourceModel\Category; | ||
|
||
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Store\Model\ScopeInterface; | ||
|
||
/** | ||
* Category resource collection | ||
* | ||
* @api | ||
* @author Magento Core Team <[email protected]> | ||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) | ||
* @since 100.0.2 | ||
*/ | ||
class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection | ||
|
@@ -58,6 +61,61 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\Abstrac | |
*/ | ||
protected $_loadWithProductCount = false; | ||
|
||
/** | ||
* Core store config | ||
* | ||
* @var \Magento\Framework\App\Config\ScopeConfigInterface | ||
*/ | ||
private $scopeConfig; | ||
|
||
/** | ||
* Constructor | ||
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory | ||
* @param \Psr\Log\LoggerInterface $logger | ||
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy | ||
* @param \Magento\Framework\Event\ManagerInterface $eventManager | ||
* @param \Magento\Eav\Model\Config $eavConfig | ||
* @param \Magento\Framework\App\ResourceConnection $resource | ||
* @param \Magento\Eav\Model\EntityFactory $eavEntityFactory | ||
* @param \Magento\Eav\Model\ResourceModel\Helper $resourceHelper | ||
* @param \Magento\Framework\Validator\UniversalFactory $universalFactory | ||
* @param \Magento\Store\Model\StoreManagerInterface $storeManager | ||
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection | ||
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig | ||
* | ||
* @SuppressWarnings(PHPMD.ExcessiveParameterList) | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\Data\Collection\EntityFactory $entityFactory, | ||
\Psr\Log\LoggerInterface $logger, | ||
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, | ||
\Magento\Framework\Event\ManagerInterface $eventManager, | ||
\Magento\Eav\Model\Config $eavConfig, | ||
\Magento\Framework\App\ResourceConnection $resource, | ||
\Magento\Eav\Model\EntityFactory $eavEntityFactory, | ||
\Magento\Eav\Model\ResourceModel\Helper $resourceHelper, | ||
\Magento\Framework\Validator\UniversalFactory $universalFactory, | ||
\Magento\Store\Model\StoreManagerInterface $storeManager, | ||
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null, | ||
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig = null | ||
) { | ||
parent::__construct( | ||
$entityFactory, | ||
$logger, | ||
$fetchStrategy, | ||
$eventManager, | ||
$eavConfig, | ||
$resource, | ||
$eavEntityFactory, | ||
$resourceHelper, | ||
$universalFactory, | ||
$storeManager, | ||
$connection | ||
); | ||
$this->scopeConfig = $scopeConfig ?: | ||
\Magento\Framework\App\ObjectManager::getInstance()->get(ScopeConfigInterface::class); | ||
} | ||
|
||
/** | ||
* Init collection and determine table names | ||
* | ||
|
@@ -402,6 +460,23 @@ public function addRootLevelFilter() | |
return $this; | ||
} | ||
|
||
/** | ||
* Add navigation max depth filter | ||
* | ||
* @return $this | ||
*/ | ||
public function addNavigationMaxDepthFilter() | ||
{ | ||
$navigationMaxDepth = (int)$this->scopeConfig->getValue( | ||
'catalog/navigation/max_depth', | ||
ScopeInterface::SCOPE_STORE | ||
); | ||
if ($navigationMaxDepth > 0) { | ||
$this->addLevelFilter($navigationMaxDepth); | ||
} | ||
return $this; | ||
} | ||
|
||
/** | ||
* Add order field | ||
* | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,25 @@ | |
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Model\ResourceModel\Category\Flat; | ||
|
||
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\App\ObjectManager; | ||
use Magento\Framework\Data\Collection\EntityFactory; | ||
use Magento\Framework\Event\ManagerInterface; | ||
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface; | ||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb; | ||
use Psr\Log\LoggerInterface as Logger; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\Store\Model\ScopeInterface; | ||
|
||
/** | ||
* Catalog category flat collection | ||
* | ||
* @author Magento Core Team <[email protected]> | ||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) | ||
*/ | ||
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection | ||
{ | ||
|
@@ -48,6 +53,13 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab | |
*/ | ||
protected $_storeId; | ||
|
||
/** | ||
* Store config. | ||
* | ||
* @var ScopeConfigInterface | ||
*/ | ||
private $scopeConfig; | ||
|
||
/** | ||
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory | ||
* @param Logger $logger | ||
|
@@ -56,6 +68,7 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab | |
* @param \Magento\Store\Model\StoreManagerInterface $storeManager | ||
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection | ||
* @param AbstractDb $resource | ||
* @param ScopeConfigInterface $scopeConfig | ||
*/ | ||
public function __construct( | ||
EntityFactory $entityFactory, | ||
|
@@ -64,9 +77,11 @@ public function __construct( | |
ManagerInterface $eventManager, | ||
StoreManagerInterface $storeManager, | ||
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null, | ||
AbstractDb $resource = null | ||
AbstractDb $resource = null, | ||
ScopeConfigInterface $scopeConfig = null | ||
) { | ||
$this->_storeManager = $storeManager; | ||
$this->scopeConfig = $scopeConfig ?? ObjectManager::getInstance()->get(ScopeConfigInterface::class); | ||
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource); | ||
} | ||
|
||
|
@@ -387,4 +402,22 @@ public function setPage($pageNum, $pageSize) | |
$this->setCurPage($pageNum)->setPageSize($pageSize); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Add navigation max depth filter. | ||
* | ||
* @return $this | ||
*/ | ||
public function addNavigationMaxDepthFilter() | ||
{ | ||
$navigationMaxDepth = (int)$this->scopeConfig->getValue( | ||
'catalog/navigation/max_depth', | ||
ScopeInterface::SCOPE_STORE | ||
); | ||
if ($navigationMaxDepth > 0) { | ||
$this->addLevelFilter($navigationMaxDepth); | ||
} | ||
|
||
return $this; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding public methods to API classes in patch releases is prrrohibited by our backward compatibility policy