Skip to content

Commit b567c48

Browse files
committed
B2B-2469: Improve category children loading
- style fix
1 parent b3a6f38 commit b567c48

File tree

1 file changed

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

1 file changed

+15
-10
lines changed

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,26 @@ public function __construct(Hydrator $hydrator)
4444
*/
4545
public function forge(Category $category): void
4646
{
47-
$pathElements = explode('/', $category->getPath());
47+
$pathElements = array_map(
48+
function($element) {
49+
return (int)$element;
50+
},
51+
explode('/', $category->getPath())
52+
);
4853
$parentId = null;
49-
foreach ($pathElements as $pathElement) {
54+
foreach ($pathElements as $id) {
5055
if ($parentId && $this->hasNodeById($parentId)) {
51-
if (!$this->hasNodeById((int)$pathElement)) {
52-
$this->indexById[(int)$pathElement] = new Node((int)$pathElement, $this);
53-
$this->getNodeById($parentId)->addChild($this->indexById[(int)$pathElement]);
54-
if ($category->getId() == $pathElement) {
55-
$this->indexById[(int)$pathElement]->setModel($category);
56+
if (!$this->hasNodeById($id)) {
57+
$this->indexById[$id] = new Node($id, $this);
58+
$this->getNodeById($parentId)->addChild($this->indexById[$id]);
59+
if ($category->getId() == $id) {
60+
$this->indexById[$id]->setModel($category);
5661
}
5762
}
58-
} elseif (!$this->hasNodeById((int)$pathElement)) {
59-
$this->indexById[(int)$pathElement] = new Node((int)$pathElement, $this);
63+
} elseif (!$this->hasNodeById($id)) {
64+
$this->indexById[$id] = new Node($id, $this);
6065
}
61-
$parentId = (int) $pathElement;
66+
$parentId = $id;
6267
}
6368
}
6469

0 commit comments

Comments
 (0)