File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,8 @@ public function execute(\Iterator $iterator): array
67
67
$ tree = $ this ->mergeCategoriesTrees ($ currentLevelTree , $ tree );
68
68
}
69
69
}
70
- return $ tree ;
70
+
71
+ return $ this ->sortTree ($ tree );
71
72
}
72
73
73
74
/**
@@ -141,4 +142,24 @@ private function explodePathToArray(array $pathElements, int $index): array
141
142
}
142
143
return $ tree ;
143
144
}
145
+
146
+ /**
147
+ * Recursive method to sort tree
148
+ *
149
+ * @param array $tree
150
+ * @return array
151
+ */
152
+ private function sortTree (array $ tree ): array
153
+ {
154
+ foreach ($ tree as &$ node ) {
155
+ if ($ node ['children ' ]) {
156
+ uasort ($ node ['children ' ], function ($ element1 , $ element2 ) {
157
+ return $ element1 ['position ' ] > $ element2 ['position ' ];
158
+ });
159
+ $ node ['children ' ] = $ this ->sortTree ($ node ['children ' ]);
160
+ }
161
+ }
162
+
163
+ return $ tree ;
164
+ }
144
165
}
You can’t perform that action at this time.
0 commit comments