Skip to content

Commit e06c1d7

Browse files
committed
B2B-2469: Improve category children loading
- CR fixes
1 parent 7ce4a77 commit e06c1d7

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryList.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
103103
*
104104
* @param array $topLevelCategoryIds
105105
* @param ResolveInfo $info
106-
* @param array $criteria
106+
* @param array $processedArgs
107107
* @param array $attributeNames
108108
* @param ContextInterface $context
109109
* @return array
@@ -112,13 +112,14 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
112112
private function fetchCategoriesByTopLevelIds(
113113
array $topLevelCategoryIds,
114114
ResolveInfo $info,
115-
array $criteria,
115+
array $processedArgs,
116116
array $attributeNames,
117117
ContextInterface $context
118118
) : array {
119-
$criteria['pageSize'] = 0;
119+
// pagination must be applied to top level category results, children categories are not paginated
120+
$processedArgs['pageSize'] = 0;
120121
$searchCriteria = $this->searchCriteria->buildCriteria(
121-
$criteria,
122+
$processedArgs,
122123
$context->getExtensionAttributes()->getStore()
123124
);
124125
$categoryCollection = $this->categoryTree->getFlatCategoriesByRootIds(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function getId(): int
8181
}
8282

8383
/**
84-
* Render node and its children as an array recursively, returns null is node model is not set.
84+
* Render node and its children as an array recursively, returns null if node data is not set.
8585
*
8686
* @return array|null
8787
*/

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ class NodeWrapper
2222
private const TOP_NODE_ID = 0;
2323

2424
/**
25-
* Flat index of the tree.
25+
* Flat index of the tree that stores nodes by entity identifier.
2626
*
2727
* @var array
2828
*/
29-
private array $index = [];
29+
private array $nodesById = [];
3030

3131
/**
3232
* @var Hydrator
@@ -49,21 +49,21 @@ public function __construct(Hydrator $hydrator)
4949
*/
5050
public function wrap(Category $category): void
5151
{
52-
if (!isset($this->index[self::TOP_NODE_ID])) {
53-
$this->index[self::TOP_NODE_ID] = new Node(self::TOP_NODE_ID);
52+
if (!isset($this->nodesById[self::TOP_NODE_ID])) {
53+
$this->nodesById[self::TOP_NODE_ID] = new Node(self::TOP_NODE_ID);
5454
}
5555
$parentId = self::TOP_NODE_ID;
5656
array_map(
5757
function ($id) use (&$parentId, $category) {
5858
$id = (int)$id;
59-
if (!isset($this->index[$id])) {
60-
$this->index[$id] = new Node($id);
59+
if (!isset($this->nodesById[$id])) {
60+
$this->nodesById[$id] = new Node($id);
6161
if ($category->getId() == $id) {
62-
$this->index[$id]->setModelData(
62+
$this->nodesById[$id]->setModelData(
6363
$this->hydrator->hydrateCategory($category)
6464
);
6565
}
66-
$this->index[$parentId]->addChild($this->index[$id]);
66+
$this->nodesById[$parentId]->addChild($this->nodesById[$id]);
6767
}
6868
$parentId = $id;
6969
},
@@ -77,8 +77,8 @@ function ($id) use (&$parentId, $category) {
7777
* @param int $id
7878
* @return Node|null
7979
*/
80-
public function getNode(int $id) : ?Node
80+
public function getNodeById(int $id) : ?Node
8181
{
82-
return $this->index[$id] ?? null;
82+
return $this->nodesById[$id] ?? null;
8383
}
8484
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function buildTree(Collection $collection, array $topLevelCategories) : a
4545
}
4646
$tree = [];
4747
foreach ($topLevelCategories as $topLevelCategory) {
48-
$tree[] = $wrapper->getNode($topLevelCategory)->renderArray();
48+
$tree[] = $wrapper->getNodeById($topLevelCategory)->renderArray();
4949
}
5050
return $this->sortTree($tree);
5151
}

0 commit comments

Comments
 (0)