5
5
*/
6
6
namespace Magento \Catalog \Model \Category ;
7
7
8
+ use Magento \Catalog \Api \Data \CategoryTreeInterface ;
9
+ use Magento \Catalog \Api \Data \CategoryTreeInterfaceFactory ;
10
+ use Magento \Catalog \Model \Category ;
11
+ use Magento \Catalog \Model \ResourceModel \Category \Collection ;
12
+ use Magento \Catalog \Model \ResourceModel \Category \TreeFactory ;
13
+ use Magento \Framework \App \ObjectManager ;
8
14
use Magento \Framework \Data \Tree \Node ;
15
+ use Magento \Framework \Exception \LocalizedException ;
16
+ use Magento \Framework \Exception \NoSuchEntityException ;
17
+ use Magento \Store \Model \StoreManagerInterface ;
9
18
10
19
/**
11
20
* Retrieve category data represented in tree structure
@@ -18,54 +27,54 @@ class Tree
18
27
protected $ categoryTree ;
19
28
20
29
/**
21
- * @var \Magento\Store\Model\ StoreManagerInterface
30
+ * @var StoreManagerInterface
22
31
*/
23
32
protected $ storeManager ;
24
33
25
34
/**
26
- * @var \Magento\Catalog\Model\ResourceModel\Category\ Collection
35
+ * @var Collection
27
36
*/
28
37
protected $ categoryCollection ;
29
38
30
39
/**
31
- * @var \Magento\Catalog\Api\Data\ CategoryTreeInterfaceFactory
40
+ * @var CategoryTreeInterfaceFactory
32
41
*/
33
42
protected $ treeFactory ;
34
43
35
44
/**
36
- * @var \Magento\Catalog\Model\ResourceModel\Category\ TreeFactory
45
+ * @var TreeFactory
37
46
*/
38
47
private $ treeResourceFactory ;
39
48
40
49
/**
41
50
* @param \Magento\Catalog\Model\ResourceModel\Category\Tree $categoryTree
42
- * @param \Magento\Store\Model\ StoreManagerInterface $storeManager
43
- * @param \Magento\Catalog\Model\ResourceModel\Category\ Collection $categoryCollection
44
- * @param \Magento\Catalog\Api\Data\ CategoryTreeInterfaceFactory $treeFactory
45
- * @param \Magento\Catalog\Model\ResourceModel\Category\ TreeFactory|null $treeResourceFactory
51
+ * @param StoreManagerInterface $storeManager
52
+ * @param Collection $categoryCollection
53
+ * @param CategoryTreeInterfaceFactory $treeFactory
54
+ * @param TreeFactory|null $treeResourceFactory
46
55
*/
47
56
public function __construct (
48
57
\Magento \Catalog \Model \ResourceModel \Category \Tree $ categoryTree ,
49
- \ Magento \ Store \ Model \ StoreManagerInterface $ storeManager ,
50
- \ Magento \ Catalog \ Model \ ResourceModel \ Category \ Collection $ categoryCollection ,
51
- \ Magento \ Catalog \ Api \ Data \ CategoryTreeInterfaceFactory $ treeFactory ,
52
- \ Magento \ Catalog \ Model \ ResourceModel \ Category \ TreeFactory $ treeResourceFactory = null
58
+ StoreManagerInterface $ storeManager ,
59
+ Collection $ categoryCollection ,
60
+ CategoryTreeInterfaceFactory $ treeFactory ,
61
+ TreeFactory $ treeResourceFactory = null
53
62
) {
54
63
$ this ->categoryTree = $ categoryTree ;
55
64
$ this ->storeManager = $ storeManager ;
56
65
$ this ->categoryCollection = $ categoryCollection ;
57
66
$ this ->treeFactory = $ treeFactory ;
58
- $ this ->treeResourceFactory = $ treeResourceFactory ?? \ Magento \ Framework \ App \ ObjectManager::getInstance ()
59
- ->get (\ Magento \ Catalog \ Model \ ResourceModel \ Category \ TreeFactory::class);
67
+ $ this ->treeResourceFactory = $ treeResourceFactory ?? ObjectManager::getInstance ()
68
+ ->get (TreeFactory::class);
60
69
}
61
70
62
71
/**
63
72
* Get root node by category.
64
73
*
65
- * @param \Magento\Catalog\Model\ Category|null $category
74
+ * @param Category|null $category
66
75
* @return Node|null
67
- * @throws \Magento\Framework\Exception\ LocalizedException
68
- * @throws \Magento\Framework\Exception\ NoSuchEntityException
76
+ * @throws LocalizedException
77
+ * @throws NoSuchEntityException
69
78
*/
70
79
public function getRootNode ($ category = null )
71
80
{
@@ -86,28 +95,28 @@ public function getRootNode($category = null)
86
95
/**
87
96
* Get node by category.
88
97
*
89
- * @param \Magento\Catalog\Model\ Category $category
98
+ * @param Category $category
90
99
* @return Node
91
- * @throws \Magento\Framework\Exception\ LocalizedException
92
- * @throws \Magento\Framework\Exception\ NoSuchEntityException
100
+ * @throws LocalizedException
101
+ * @throws NoSuchEntityException
93
102
*/
94
- protected function getNode (\ Magento \ Catalog \ Model \ Category $ category )
103
+ protected function getNode (Category $ category )
95
104
{
96
105
$ nodeId = $ category ->getId ();
97
106
$ categoryTree = $ this ->treeResourceFactory ->create ();
98
107
$ node = $ categoryTree ->loadNode ($ nodeId );
99
108
$ node ->loadChildren ();
100
109
$ this ->prepareCollection ();
101
- $ this -> categoryTree ->addCollectionData ($ this ->categoryCollection );
110
+ $ categoryTree ->addCollectionData ($ this ->categoryCollection );
102
111
return $ node ;
103
112
}
104
113
105
114
/**
106
115
* Prepare category collection.
107
116
*
108
117
* @return void
109
- * @throws \Magento\Framework\Exception\ LocalizedException
110
- * @throws \Magento\Framework\Exception\ NoSuchEntityException
118
+ * @throws LocalizedException
119
+ * @throws NoSuchEntityException
111
120
*/
112
121
protected function prepareCollection ()
113
122
{
@@ -128,16 +137,16 @@ protected function prepareCollection()
128
137
/**
129
138
* Get tree by node.
130
139
*
131
- * @param \Magento\Framework\Data\Tree\ Node $node
140
+ * @param Node $node
132
141
* @param int $depth
133
142
* @param int $currentLevel
134
- * @return \Magento\Catalog\Api\Data\ CategoryTreeInterface
143
+ * @return CategoryTreeInterface
135
144
*/
136
145
public function getTree ($ node , $ depth = null , $ currentLevel = 0 )
137
146
{
138
- /** @var \Magento\Catalog\Api\Data\ CategoryTreeInterface[] $children */
147
+ /** @var CategoryTreeInterface[] $children */
139
148
$ children = $ this ->getChildren ($ node , $ depth , $ currentLevel );
140
- /** @var \Magento\Catalog\Api\Data\ CategoryTreeInterface $tree */
149
+ /** @var CategoryTreeInterface $tree */
141
150
$ tree = $ this ->treeFactory ->create ();
142
151
$ tree ->setId ($ node ->getId ())
143
152
->setParentId ($ node ->getParentId ())
@@ -153,10 +162,10 @@ public function getTree($node, $depth = null, $currentLevel = 0)
153
162
/**
154
163
* Get node children.
155
164
*
156
- * @param \Magento\Framework\Data\Tree\ Node $node
165
+ * @param Node $node
157
166
* @param int $depth
158
167
* @param int $currentLevel
159
- * @return \Magento\Catalog\Api\Data\ CategoryTreeInterface[]|[]
168
+ * @return CategoryTreeInterface[]|[]
160
169
*/
161
170
protected function getChildren ($ node , $ depth , $ currentLevel )
162
171
{
0 commit comments