Skip to content

Commit 9ebe65b

Browse files
committed
B2B-2469: Improve category children loading
- codestyle fixes:
1 parent 01261c0 commit 9ebe65b

File tree

5 files changed

+18
-21
lines changed

5 files changed

+18
-21
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
9595
throw new GraphQlInputException(__($e->getMessage()));
9696
}
9797

98-
$result = $this->fetchCategoriesByTopLevelIds($topLevelCategoryIds, $info, $processedArgs, $store, [], $context);
99-
100-
return $result;
98+
return $this->fetchCategoriesByTopLevelIds($topLevelCategoryIds, $info, $processedArgs, $store, [], $context);
10199
}
102100

103101
/**
@@ -113,12 +111,12 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
113111
* @throws LocalizedException
114112
*/
115113
private function fetchCategoriesByTopLevelIds(
116-
array $topLevelCategoryIds,
117-
ResolveInfo $info,
118-
array $criteria,
114+
array $topLevelCategoryIds,
115+
ResolveInfo $info,
116+
array $criteria,
119117
StoreInterface $store,
120-
array $attributeNames,
121-
$context
118+
array $attributeNames,
119+
$context
122120
) : array {
123121
$criteria['pageSize'] = 0;
124122
$searchCriteria = $this->searchCriteria->buildCriteria($criteria, $store);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CategoryTree implements ResolverInterface
2424
/**
2525
* Name of type in GraphQL
2626
*/
27-
const CATEGORY_INTERFACE = 'CategoryInterface';
27+
public const CATEGORY_INTERFACE = 'CategoryInterface';
2828

2929
/**
3030
* @var CategoryTreeDataProvider
@@ -72,9 +72,9 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7272
$this->checkCategoryIsActive->execute($rootCategoryId);
7373
}
7474
$store = $context->getExtensionAttributes()->getStore();
75-
$categoriesTree = $this->categoryTree->getTreeCollection($info, $rootCategoryId, (int)$store->getId());
75+
$categoriesTree = $this->categoryTree->getTreeCollection($info, $rootCategoryId);
7676

77-
if (empty($categoriesTree) || ($categoriesTree->count() == 0)) {
77+
if ($categoriesTree->count() == 0) {
7878
throw new GraphQlNoSuchEntityException(__('Category doesn\'t exist'));
7979
}
8080

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,12 @@ public function getTree(ResolveInfo $resolveInfo, int $rootCategoryId, int $stor
116116
*
117117
* @param ResolveInfo $resolveInfo
118118
* @param int $rootCategoryId
119-
* @param int $storeId
120-
* @return Iterator
119+
* @return Collection
121120
* @throws LocalizedException
122121
* @throws Exception
123122
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
124123
*/
125-
public function getTreeCollection(ResolveInfo $resolveInfo, int $rootCategoryId, int $storeId): Collection
124+
public function getTreeCollection(ResolveInfo $resolveInfo, int $rootCategoryId): Collection
126125
{
127126
return $this->getRawCollection($resolveInfo, [$rootCategoryId]);
128127
}
@@ -237,14 +236,13 @@ public function getFilteredTree(
237236
* Returns categories tree starting from parent $rootCategoryId with filtration
238237
*
239238
* @param ResolveInfo $resolveInfo
240-
* @param int $rootCategoryId
241-
* @param array $criteria
239+
* @param array $topLevelCategoryIds
240+
* @param SearchCriteria $searchCriteria
242241
* @param StoreInterface $store
243242
* @param array $attributeNames
244243
* @param ContextInterface $context
245244
* @return Collection
246245
* @throws LocalizedException
247-
* @throws Exception
248246
*/
249247
public function getFlatCategoriesByRootIds(
250248
ResolveInfo $resolveInfo,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ public function getId(): int
105105
*/
106106
public function renderArray(): array
107107
{
108-
return array_merge($this->forgery->getHydrator()->hydrateCategory($this->model),
108+
return array_merge(
109+
$this->forgery->getHydrator()->hydrateCategory($this->model),
109110
[
110111
'children' => array_map(
111-
function($node) {
112+
function ($node) {
112113
return $node->renderArray();
113114
},
114115
$this->children

app/code/Magento/CatalogUrlRewriteGraphQl/Model/DataProvider/UrlRewrite/CatalogTreeDataProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public function getData(
6363
int $storeId = null
6464
): array {
6565
$categoryId = (int)$id;
66-
$categoriesTree = $this->categoryTree->getTreeCollection($info, $categoryId, $storeId);
67-
if (empty($categoriesTree) || ($categoriesTree->count() == 0)) {
66+
$categoriesTree = $this->categoryTree->getTreeCollection($info, $categoryId);
67+
if ($categoriesTree->count() == 0) {
6868
throw new GraphQlNoSuchEntityException(__('Category doesn\'t exist'));
6969
}
7070
$result = current($this->extractDataFromCategoryTree->buildTree($categoriesTree, [$categoryId]));

0 commit comments

Comments
 (0)