|
6 | 6 | namespace Magento\Catalog\Model\ResourceModel\Category;
|
7 | 7 |
|
8 | 8 | use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
|
| 9 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 10 | +use Magento\Store\Model\ScopeInterface; |
9 | 11 |
|
10 | 12 | /**
|
11 | 13 | * Category resource collection
|
12 | 14 | *
|
13 | 15 | * @api
|
14 | 16 | * @author Magento Core Team <[email protected]>
|
| 17 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
15 | 18 | * @since 100.0.2
|
16 | 19 | */
|
17 | 20 | class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection
|
@@ -58,6 +61,61 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\Abstrac
|
58 | 61 | */
|
59 | 62 | protected $_loadWithProductCount = false;
|
60 | 63 |
|
| 64 | + /** |
| 65 | + * Core store config |
| 66 | + * |
| 67 | + * @var \Magento\Framework\App\Config\ScopeConfigInterface |
| 68 | + */ |
| 69 | + private $scopeConfig; |
| 70 | + |
| 71 | + /** |
| 72 | + * Constructor |
| 73 | + * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory |
| 74 | + * @param \Psr\Log\LoggerInterface $logger |
| 75 | + * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy |
| 76 | + * @param \Magento\Framework\Event\ManagerInterface $eventManager |
| 77 | + * @param \Magento\Eav\Model\Config $eavConfig |
| 78 | + * @param \Magento\Framework\App\ResourceConnection $resource |
| 79 | + * @param \Magento\Eav\Model\EntityFactory $eavEntityFactory |
| 80 | + * @param \Magento\Eav\Model\ResourceModel\Helper $resourceHelper |
| 81 | + * @param \Magento\Framework\Validator\UniversalFactory $universalFactory |
| 82 | + * @param \Magento\Store\Model\StoreManagerInterface $storeManager |
| 83 | + * @param \Magento\Framework\DB\Adapter\AdapterInterface $connection |
| 84 | + * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig |
| 85 | + * |
| 86 | + * @SuppressWarnings(PHPMD.ExcessiveParameterList) |
| 87 | + */ |
| 88 | + public function __construct( |
| 89 | + \Magento\Framework\Data\Collection\EntityFactory $entityFactory, |
| 90 | + \Psr\Log\LoggerInterface $logger, |
| 91 | + \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, |
| 92 | + \Magento\Framework\Event\ManagerInterface $eventManager, |
| 93 | + \Magento\Eav\Model\Config $eavConfig, |
| 94 | + \Magento\Framework\App\ResourceConnection $resource, |
| 95 | + \Magento\Eav\Model\EntityFactory $eavEntityFactory, |
| 96 | + \Magento\Eav\Model\ResourceModel\Helper $resourceHelper, |
| 97 | + \Magento\Framework\Validator\UniversalFactory $universalFactory, |
| 98 | + \Magento\Store\Model\StoreManagerInterface $storeManager, |
| 99 | + \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, |
| 100 | + \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig = null |
| 101 | + ) { |
| 102 | + parent::__construct( |
| 103 | + $entityFactory, |
| 104 | + $logger, |
| 105 | + $fetchStrategy, |
| 106 | + $eventManager, |
| 107 | + $eavConfig, |
| 108 | + $resource, |
| 109 | + $eavEntityFactory, |
| 110 | + $resourceHelper, |
| 111 | + $universalFactory, |
| 112 | + $storeManager, |
| 113 | + $connection |
| 114 | + ); |
| 115 | + $this->scopeConfig = $scopeConfig ?: |
| 116 | + \Magento\Framework\App\ObjectManager::getInstance()->get(ScopeConfigInterface::class); |
| 117 | + } |
| 118 | + |
61 | 119 | /**
|
62 | 120 | * Init collection and determine table names
|
63 | 121 | *
|
@@ -404,6 +462,23 @@ public function addRootLevelFilter()
|
404 | 462 | return $this;
|
405 | 463 | }
|
406 | 464 |
|
| 465 | + /** |
| 466 | + * Add navigation max depth filter |
| 467 | + * |
| 468 | + * @return $this |
| 469 | + */ |
| 470 | + public function addNavigationMaxDepthFilter() |
| 471 | + { |
| 472 | + $navigationMaxDepth = (int)$this->scopeConfig->getValue( |
| 473 | + 'catalog/navigation/max_depth', |
| 474 | + ScopeInterface::SCOPE_STORE |
| 475 | + ); |
| 476 | + if ($navigationMaxDepth > 0) { |
| 477 | + $this->addLevelFilter($navigationMaxDepth); |
| 478 | + } |
| 479 | + return $this; |
| 480 | + } |
| 481 | + |
407 | 482 | /**
|
408 | 483 | * Add order field
|
409 | 484 | *
|
|
0 commit comments