Skip to content

Commit 8ca4590

Browse files
committed
GraphQL-463: Query category for disabled catalog with products returns the products count
1 parent 53d087a commit 8ca4590

File tree

1 file changed

+13
-12
lines changed
  • app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider

1 file changed

+13
-12
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\CatalogGraphQl\Model\Category\DepthCalculator;
1212
use Magento\CatalogGraphQl\Model\Category\LevelCalculator;
1313
use Magento\Framework\EntityManager\MetadataPool;
14+
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1415
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1516
use Magento\Catalog\Api\Data\CategoryInterface;
1617
use Magento\Catalog\Model\ResourceModel\Category\Collection;
@@ -84,10 +85,11 @@ public function __construct(
8485
public function getTree(ResolveInfo $resolveInfo, int $rootCategoryId): \Iterator
8586
{
8687
$categoryQuery = $resolveInfo->fieldNodes[0];
87-
$collection = $this->collectionFactory->create();
88-
if ($this->isRootCategoryActive($collection, $rootCategoryId) == false) {
89-
throw new \Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException(__('Category doesn\'t exist'));
88+
if ($this->isCategoryActive($rootCategoryId) == false) {
89+
throw new GraphQlNoSuchEntityException(__('Category doesn\'t exist'));
9090
}
91+
92+
$collection = $this->collectionFactory->create();
9193
$this->joinAttributesRecursively($collection, $categoryQuery);
9294
$depth = $this->depthCalculator->calculate($categoryQuery);
9395
$level = $this->levelCalculator->calculate($rootCategoryId);
@@ -149,27 +151,26 @@ private function joinAttributesRecursively(Collection $collection, FieldNode $fi
149151
}
150152

151153
/**
152-
* @param Collection $collection
153154
* @param int $rootCategoryId
154-
*
155155
* @return bool
156156
* @throws \Exception
157157
*/
158-
private function isRootCategoryActive(Collection $collection, int $rootCategoryId) : bool
158+
private function isCategoryActive(int $rootCategoryId) : bool
159159
{
160160
if ($rootCategoryId == Category::TREE_ROOT_ID) {
161161
return true;
162162
}
163+
$collection = $this->collectionFactory->create();
163164
$collection->addAttributeToFilter(Category::KEY_IS_ACTIVE, ['eq' => 1])
164165
->getSelect()
165166
->where(
166167
$collection->getSelect()
167-
->getConnection()
168-
->quoteIdentifier(
169-
'e.' . $this->metadata->getMetadata(CategoryInterface::class)->getIdentifierField()
170-
) . ' = ?',
171-
$rootCategoryId
168+
->getConnection()
169+
->quoteIdentifier(
170+
'e.' . $this->metadata->getMetadata(CategoryInterface::class)->getIdentifierField()
171+
) . ' = ?',
172+
$rootCategoryId
172173
);
173-
return (bool) $collection->count();
174+
return (bool)$collection->count();
174175
}
175176
}

0 commit comments

Comments
 (0)