Skip to content

Commit 9dae57e

Browse files
committed
Code review updates
1 parent c7fdfd3 commit 9dae57e

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/Query/ResolveCategoryAggregation.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ public function __construct(
7979
*
8080
* @param array $categoryFilter
8181
* @param Bucket[] $bucketList
82-
*
8382
* @return Aggregation
8483
*/
8584
public function getResolvedCategoryAggregation(array $categoryFilter, array $bucketList): Aggregation
@@ -92,7 +91,6 @@ public function getResolvedCategoryAggregation(array $categoryFilter, array $buc
9291
if (!$searchableCategoryValue || empty($values)) {
9392
return $this->aggregationFactory->create([self::BUCKETS => $bucketList]);
9493
}
95-
9694
$resolvedBucketList = $bucketList;
9795

9896
try {
@@ -110,33 +108,29 @@ public function getResolvedCategoryAggregation(array $categoryFilter, array $buc
110108
} catch (NoSuchEntityException $e) {
111109
return $this->aggregationFactory->create([self::BUCKETS => $bucketList]);
112110
}
113-
114111
$resolvedCategoryBucket = $this->bucketFactory->create(
115112
[
116113
'name' => self::CATEGORY_BUCKET,
117114
'values' => $resolvedValues
118115
]
119116
);
120-
121117
$resolvedBucketList[self::CATEGORY_BUCKET] = $resolvedCategoryBucket;
122118

123119
return $this->aggregationFactory->create([self::BUCKETS => $resolvedBucketList]);
124120
}
125121

126122
/**
127-
* Check is valid searchable category children.
123+
* Check is valid searchable category children, and return all aggregations with updated categories list.
128124
*
129125
* @param int $searchableCategoryId
130126
* @param AggregationValueInterface[] $aggregationValues
131-
*
132127
* @return AggregationValueInterface[]
133-
*
134128
* @throws NoSuchEntityException
135129
*/
136130
private function getValidCategories(int $searchableCategoryId, array $aggregationValues): array
137131
{
138-
$stareId = (int) $this->storeManager->getStore()->getId();
139-
$searchableCategory = $this->categoryRepository->get($searchableCategoryId, $stareId);
132+
$storeId = (int) $this->storeManager->getStore()->getId();
133+
$searchableCategory = $this->categoryRepository->get($searchableCategoryId, $storeId);
140134
$childrenList = $searchableCategory->getChildrenCategories();
141135
$resolvedList = [];
142136
$validChildIdList = [];
@@ -152,8 +146,8 @@ private function getValidCategories(int $searchableCategoryId, array $aggregatio
152146
foreach ($aggregationValues as $bucketValue) {
153147
$childCategoryId = (int) $bucketValue->getValue();
154148

155-
if (!in_array($childCategoryId, $validChildIdList) ||
156-
in_array($childCategoryId, $this->resolvedChildrenIds)
149+
if (!in_array($childCategoryId, $validChildIdList)
150+
|| in_array($childCategoryId, $this->resolvedChildrenIds)
157151
) {
158152
continue;
159153
}

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/Query/Search.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public function __construct(
9191
$this->fieldSelection = $fieldSelection;
9292
$this->productsProvider = $productsProvider;
9393
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
94-
$this->resolveCategoryAggregation = $resolveCategoryAggregation;
94+
$this->resolveCategoryAggregation = $resolveCategoryAggregation ?: ObjectManager::getInstance()
95+
->get(ResolveCategoryAggregation::class);
9596
$this->argsSelection = $argsSelection ?: ObjectManager::getInstance()
9697
->get(ArgumentsProcessorInterface::class);
9798
}
@@ -102,9 +103,7 @@ public function __construct(
102103
* @param array $args
103104
* @param ResolveInfo $info
104105
* @param ContextInterface $context
105-
*
106106
* @return SearchResult
107-
*
108107
* @throws GraphQlInputException
109108
*/
110109
public function getResult(
@@ -169,9 +168,7 @@ public function getResult(
169168
*
170169
* @param array $args
171170
* @param ResolveInfo $info
172-
*
173171
* @return SearchCriteriaInterface
174-
*
175172
* @throws GraphQlInputException
176173
*/
177174
private function buildSearchCriteria(array $args, ResolveInfo $info): SearchCriteriaInterface

0 commit comments

Comments
 (0)