|
11 | 11 | use Magento\CatalogGraphQl\Model\Category\DepthCalculator;
|
12 | 12 | use Magento\CatalogGraphQl\Model\Category\LevelCalculator;
|
13 | 13 | use Magento\Framework\EntityManager\MetadataPool;
|
| 14 | +use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; |
14 | 15 | use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
|
15 | 16 | use Magento\Catalog\Api\Data\CategoryInterface;
|
16 | 17 | use Magento\Catalog\Model\ResourceModel\Category\Collection;
|
@@ -84,10 +85,11 @@ public function __construct(
|
84 | 85 | public function getTree(ResolveInfo $resolveInfo, int $rootCategoryId): \Iterator
|
85 | 86 | {
|
86 | 87 | $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')); |
90 | 90 | }
|
| 91 | + |
| 92 | + $collection = $this->collectionFactory->create(); |
91 | 93 | $this->joinAttributesRecursively($collection, $categoryQuery);
|
92 | 94 | $depth = $this->depthCalculator->calculate($categoryQuery);
|
93 | 95 | $level = $this->levelCalculator->calculate($rootCategoryId);
|
@@ -149,27 +151,26 @@ private function joinAttributesRecursively(Collection $collection, FieldNode $fi
|
149 | 151 | }
|
150 | 152 |
|
151 | 153 | /**
|
152 |
| - * @param Collection $collection |
153 | 154 | * @param int $rootCategoryId
|
154 |
| - * |
155 | 155 | * @return bool
|
156 | 156 | * @throws \Exception
|
157 | 157 | */
|
158 |
| - private function isRootCategoryActive(Collection $collection, int $rootCategoryId) : bool |
| 158 | + private function isCategoryActive(int $rootCategoryId) : bool |
159 | 159 | {
|
160 | 160 | if ($rootCategoryId == Category::TREE_ROOT_ID) {
|
161 | 161 | return true;
|
162 | 162 | }
|
| 163 | + $collection = $this->collectionFactory->create(); |
163 | 164 | $collection->addAttributeToFilter(Category::KEY_IS_ACTIVE, ['eq' => 1])
|
164 | 165 | ->getSelect()
|
165 | 166 | ->where(
|
166 | 167 | $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 |
172 | 173 | );
|
173 |
| - return (bool) $collection->count(); |
| 174 | + return (bool)$collection->count(); |
174 | 175 | }
|
175 | 176 | }
|
0 commit comments