Skip to content

Commit 6703f60

Browse files
committed
B2B-2469: Improve category children loading
- added very top root node dummy for proper tree handling
1 parent 534aa0a commit 6703f60

File tree

1 file changed

+10
-2
lines changed
  • app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree/Wrapper

1 file changed

+10
-2
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree/Wrapper/Forgery.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
*/
1717
class Forgery
1818
{
19+
/**
20+
* Most top node id in the tree structure.
21+
*/
22+
private const DUMMY_ROOT_ID = 0;
23+
1924
/**
2025
* Flat index of the tree.
2126
*
@@ -50,9 +55,12 @@ function ($element) {
5055
},
5156
explode('/', $category->getPath())
5257
);
53-
$parentId = null;
58+
if (!$this->hasNodeById(self::DUMMY_ROOT_ID)) {
59+
$this->indexById[self::DUMMY_ROOT_ID] = new Node(self::DUMMY_ROOT_ID, $this);
60+
}
61+
$parentId = self::DUMMY_ROOT_ID;
5462
foreach ($pathElements as $id) {
55-
if ($parentId && $this->hasNodeById($parentId)) {
63+
if ($this->hasNodeById($parentId)) {
5664
if (!$this->hasNodeById($id)) {
5765
$this->indexById[$id] = new Node($id, $this);
5866
$this->getNodeById($parentId)->addChild($this->indexById[$id]);

0 commit comments

Comments
 (0)