12
12
use Magento \Framework \Model \ResourceModel \Db \AbstractDb ;
13
13
use Psr \Log \LoggerInterface as Logger ;
14
14
use Magento \Store \Model \StoreManagerInterface ;
15
+ use Magento \Store \Model \ScopeInterface ;
15
16
16
17
/**
17
18
* Catalog category flat collection
@@ -48,12 +49,20 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
48
49
*/
49
50
protected $ _storeId ;
50
51
52
+ /**
53
+ * Core store config
54
+ *
55
+ * @var \Magento\Framework\App\Config\ScopeConfigInterface
56
+ */
57
+ private $ scopeConfig ;
58
+
51
59
/**
52
60
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
53
61
* @param Logger $logger
54
62
* @param FetchStrategyInterface $fetchStrategy
55
63
* @param ManagerInterface $eventManager
56
64
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
65
+ * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
57
66
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
58
67
* @param AbstractDb $resource
59
68
*/
@@ -63,10 +72,12 @@ public function __construct(
63
72
FetchStrategyInterface $ fetchStrategy ,
64
73
ManagerInterface $ eventManager ,
65
74
StoreManagerInterface $ storeManager ,
75
+ \Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig ,
66
76
\Magento \Framework \DB \Adapter \AdapterInterface $ connection = null ,
67
77
AbstractDb $ resource = null
68
78
) {
69
79
$ this ->_storeManager = $ storeManager ;
80
+ $ this ->scopeConfig = $ scopeConfig ;
70
81
parent ::__construct ($ entityFactory , $ logger , $ fetchStrategy , $ eventManager , $ connection , $ resource );
71
82
}
72
83
@@ -387,4 +398,21 @@ public function setPage($pageNum, $pageSize)
387
398
$ this ->setCurPage ($ pageNum )->setPageSize ($ pageSize );
388
399
return $ this ;
389
400
}
401
+
402
+ /**
403
+ * Add navigation max depth filter
404
+ *
405
+ * @return $this
406
+ */
407
+ public function addNavigationMaxDepthFilter ()
408
+ {
409
+ $ navigationMaxDepth = (int )$ this ->scopeConfig ->getValue (
410
+ 'catalog/navigation/max_depth ' ,
411
+ ScopeInterface::SCOPE_STORE
412
+ );
413
+ if ($ navigationMaxDepth > 0 ) {
414
+ $ this ->addLevelFilter ($ navigationMaxDepth );
415
+ }
416
+ return $ this ;
417
+ }
390
418
}
0 commit comments