@@ -94,86 +94,19 @@ public function __construct(
94
94
$ this ->collectionProcessor = $ collectionProcessor ;
95
95
}
96
96
97
- /**
98
- * Returns categories tree starting from parent $rootCategoryId
99
- *
100
- * @param ResolveInfo $resolveInfo
101
- * @param int $rootCategoryId
102
- * @param int $storeId
103
- * @return Iterator
104
- * @throws LocalizedException
105
- * @throws Exception
106
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
107
- */
108
- public function getTree (ResolveInfo $ resolveInfo , int $ rootCategoryId , int $ storeId ): Iterator
109
- {
110
- $ collection = $ this ->getCollection ($ resolveInfo , $ rootCategoryId );
111
- return $ collection ->getIterator ();
112
- }
113
-
114
97
/**
115
98
* Returns categories collection for tree starting from parent $rootCategoryId
116
99
*
117
100
* @param ResolveInfo $resolveInfo
118
101
* @param int $rootCategoryId
102
+ * @param int $storeId
119
103
* @return Collection
120
104
* @throws LocalizedException
121
- * @throws Exception
122
105
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
123
106
*/
124
- public function getTreeCollection (ResolveInfo $ resolveInfo , int $ rootCategoryId ): Collection
107
+ public function getTreeCollection (ResolveInfo $ resolveInfo , int $ rootCategoryId, int $ storeId ): Collection
125
108
{
126
- return $ this ->getRawCollection ($ resolveInfo , [$ rootCategoryId ]);
127
- }
128
-
129
- /**
130
- * Return prepared collection
131
- *
132
- * @param ResolveInfo $resolveInfo
133
- * @param int $rootCategoryId
134
- * @return Collection
135
- * @throws LocalizedException
136
- * @throws Exception
137
- */
138
- private function getCollection (ResolveInfo $ resolveInfo , int $ rootCategoryId ) : Collection
139
- {
140
- $ categoryQuery = $ resolveInfo ->fieldNodes [0 ];
141
- $ collection = $ this ->collectionFactory ->create ();
142
- $ this ->joinAttributesRecursively ($ collection , $ categoryQuery , $ resolveInfo );
143
- $ depth = $ this ->depthCalculator ->calculate ($ resolveInfo , $ categoryQuery );
144
- $ level = $ this ->levelCalculator ->calculate ($ rootCategoryId );
145
-
146
- // If root category is being filter, we've to remove first slash
147
- if ($ rootCategoryId == Category::TREE_ROOT_ID ) {
148
- $ regExpPathFilter = sprintf ('.*%s/[/0-9]*$ ' , $ rootCategoryId );
149
- } else {
150
- $ regExpPathFilter = sprintf ('.*/%s/[/0-9]*$ ' , $ rootCategoryId );
151
- }
152
-
153
- //Add `is_anchor` attribute to selected field
154
- $ collection ->addAttributeToSelect ('is_anchor ' );
155
-
156
- //Search for desired part of category tree
157
- $ collection ->addPathFilter ($ regExpPathFilter );
158
-
159
- $ collection ->addFieldToFilter ('level ' , ['gt ' => $ level ]);
160
- $ collection ->addFieldToFilter ('level ' , ['lteq ' => $ level + $ depth - self ::DEPTH_OFFSET ]);
161
- $ collection ->addAttributeToFilter ('is_active ' , 1 , "left " );
162
- $ collection ->setOrder ('level ' );
163
- $ collection ->setOrder (
164
- 'position ' ,
165
- $ collection ::SORT_ORDER_DESC
166
- );
167
- $ collection ->getSelect ()->orWhere (
168
- $ collection ->getSelect ()
169
- ->getConnection ()
170
- ->quoteIdentifier (
171
- 'e. ' . $ this ->metadata ->getMetadata (CategoryInterface::class)->getIdentifierField ()
172
- ) . ' = ? ' ,
173
- $ rootCategoryId
174
- );
175
-
176
- return $ collection ;
109
+ return $ this ->getRawTreeCollection ($ resolveInfo , [$ rootCategoryId ]);
177
110
}
178
111
179
112
/**
@@ -205,33 +138,6 @@ private function joinAttributesRecursively(
205
138
}
206
139
}
207
140
208
- /**
209
- * Returns categories tree starting from parent $rootCategoryId with filtration
210
- *
211
- * @param ResolveInfo $resolveInfo
212
- * @param int $rootCategoryId
213
- * @param SearchCriteria $searchCriteria
214
- * @param StoreInterface $store
215
- * @param array $attributeNames
216
- * @param ContextInterface $context
217
- * @return Iterator
218
- * @throws LocalizedException
219
- * @throws Exception
220
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
221
- */
222
- public function getFilteredTree (
223
- ResolveInfo $ resolveInfo ,
224
- int $ rootCategoryId ,
225
- SearchCriteria $ searchCriteria ,
226
- StoreInterface $ store ,
227
- array $ attributeNames ,
228
- ContextInterface $ context
229
- ): Iterator {
230
- $ collection = $ this ->getCollection ($ resolveInfo , $ rootCategoryId );
231
- $ this ->collectionProcessor ->process ($ collection , $ searchCriteria , $ attributeNames , $ context );
232
- return $ collection ->getIterator ();
233
- }
234
-
235
141
/**
236
142
* Returns categories tree starting from parent $rootCategoryId with filtration
237
143
*
@@ -252,7 +158,7 @@ public function getFlatCategoriesByRootIds(
252
158
array $ attributeNames ,
253
159
ContextInterface $ context
254
160
): Collection {
255
- $ collection = $ this ->getRawCollection ($ resolveInfo , $ topLevelCategoryIds );
161
+ $ collection = $ this ->getRawTreeCollection ($ resolveInfo , $ topLevelCategoryIds );
256
162
$ this ->collectionProcessor ->process ($ collection , $ searchCriteria , $ attributeNames , $ context );
257
163
return $ collection ;
258
164
}
@@ -261,12 +167,11 @@ public function getFlatCategoriesByRootIds(
261
167
* Return prepared collection
262
168
*
263
169
* @param ResolveInfo $resolveInfo
264
- * @param int $rootCategoryId
170
+ * @param array $topLevelCategoryIds
265
171
* @return Collection
266
172
* @throws LocalizedException
267
- * @throws Exception
268
173
*/
269
- private function getRawCollection (ResolveInfo $ resolveInfo , array $ topLevelCategoryIds ) : Collection
174
+ private function getRawTreeCollection (ResolveInfo $ resolveInfo , array $ topLevelCategoryIds ) : Collection
270
175
{
271
176
$ categoryQuery = $ resolveInfo ->fieldNodes [0 ];
272
177
$ collection = $ this ->collectionFactory ->create ();
0 commit comments