Skip to content

Commit 53d087a

Browse files
committed
Merge remote-tracking branch 'XxXgeoXxX/2.3-devlop#463' into 2.3-devlop#463
2 parents 058135b + e1aa929 commit 53d087a

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7979
}
8080

8181
$result = $this->extractDataFromCategoryTree->execute($categoriesTree);
82-
83-
$category = current($result);
84-
if ($category['is_active'] == false) {
85-
throw new GraphQlNoSuchEntityException(__('Category doesn\'t exist'));
86-
}
87-
88-
return $category;
82+
return current($result);
8983
}
9084
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ public function getTree(ResolveInfo $resolveInfo, int $rootCategoryId): \Iterato
8585
{
8686
$categoryQuery = $resolveInfo->fieldNodes[0];
8787
$collection = $this->collectionFactory->create();
88+
if ($this->isRootCategoryActive($collection, $rootCategoryId) == false) {
89+
throw new \Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException(__('Category doesn\'t exist'));
90+
}
8891
$this->joinAttributesRecursively($collection, $categoryQuery);
8992
$depth = $this->depthCalculator->calculate($categoryQuery);
9093
$level = $this->levelCalculator->calculate($rootCategoryId);
@@ -144,4 +147,29 @@ private function joinAttributesRecursively(Collection $collection, FieldNode $fi
144147
$this->joinAttributesRecursively($collection, $node);
145148
}
146149
}
150+
151+
/**
152+
* @param Collection $collection
153+
* @param int $rootCategoryId
154+
*
155+
* @return bool
156+
* @throws \Exception
157+
*/
158+
private function isRootCategoryActive(Collection $collection, int $rootCategoryId) : bool
159+
{
160+
if ($rootCategoryId == Category::TREE_ROOT_ID) {
161+
return true;
162+
}
163+
$collection->addAttributeToFilter(Category::KEY_IS_ACTIVE, ['eq' => 1])
164+
->getSelect()
165+
->where(
166+
$collection->getSelect()
167+
->getConnection()
168+
->quoteIdentifier(
169+
'e.' . $this->metadata->getMetadata(CategoryInterface::class)->getIdentifierField()
170+
) . ' = ?',
171+
$rootCategoryId
172+
);
173+
return (bool) $collection->count();
174+
}
147175
}

0 commit comments

Comments
 (0)