Skip to content

Commit 01cc2c3

Browse files
committed
MC-41473: Subcategory order changes not correct in Graphql
1 parent 7c6b636 commit 01cc2c3

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public function execute(\Iterator $iterator): array
6767
$tree = $this->mergeCategoriesTrees($currentLevelTree, $tree);
6868
}
6969
}
70-
return $tree;
70+
71+
return $this->sortTree($tree);
7172
}
7273

7374
/**
@@ -141,4 +142,24 @@ private function explodePathToArray(array $pathElements, int $index): array
141142
}
142143
return $tree;
143144
}
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+
}
144165
}

0 commit comments

Comments
 (0)