13
13
use Magento \Catalog \Api \Data \CategoryInterface ;
14
14
use Magento \Framework \EntityManager \MetadataPool ;
15
15
use Magento \Framework \Profiler ;
16
+ use Magento \Catalog \Model \ResourceModel \Category \CollectionFactory ;
16
17
17
18
class Category extends AbstractNode
18
19
{
@@ -21,6 +22,11 @@ class Category extends AbstractNode
21
22
*/
22
23
private $ metadataPool ;
23
24
25
+ /**
26
+ * @var CollectionFactory
27
+ */
28
+ private $ categoryCollection ;
29
+
24
30
/**
25
31
* @inheritDoc
26
32
*/
@@ -35,12 +41,15 @@ protected function _construct()
35
41
*
36
42
* @param Profiler $profiler
37
43
* @param MetadataPool $metadataPool
44
+ * @param CollectionFactory $categoryCollection
38
45
*/
39
46
public function __construct (
40
47
Profiler $ profiler ,
41
- MetadataPool $ metadataPool
48
+ MetadataPool $ metadataPool ,
49
+ CollectionFactory $ categoryCollection
42
50
) {
43
51
$ this ->metadataPool = $ metadataPool ;
52
+ $ this ->categoryCollection = $ categoryCollection ;
44
53
parent ::__construct ($ profiler );
45
54
}
46
55
@@ -104,9 +113,33 @@ public function fetchData(array $nodes, $storeId)
104
113
}
105
114
106
115
$ categoryUrls = $ this ->getResource ()->fetchData ($ storeId , $ categoryIds );
116
+ $ categories = $ this ->getCategories ($ storeId , $ categoryIds );
107
117
108
118
$ this ->profiler ->stop (__METHOD__ );
109
119
110
- return [$ localNodes , $ categoryUrls ];
120
+ return [$ localNodes , $ categoryUrls , $ categories ];
121
+ }
122
+
123
+ /**
124
+ * @param int|string|\Magento\Store\Model\Store $store
125
+ * @param array $categoryIds
126
+ * @return array
127
+ */
128
+ public function getCategories ($ store , array $ categoryIds )
129
+ {
130
+ $ return = [];
131
+ $ categories = $ this ->categoryCollection ->create ()
132
+ ->addAttributeToSelect ('* ' )
133
+ ->setStoreId ($ store )
134
+ ->addFieldToFilter (
135
+ 'entity_id ' ,
136
+ ['in ' => $ categoryIds ]
137
+ );
138
+
139
+ foreach ($ categories as $ category ) {
140
+ $ return [$ category ->getId ()] = $ category ;
141
+ }
142
+
143
+ return $ return ;
111
144
}
112
145
}
0 commit comments