From d452a36e32955fbb76ae14d8b57298a6816e5199 Mon Sep 17 00:00:00 2001 From: Ievgenii Gryshkun Date: Fri, 15 Mar 2019 13:04:30 +0200 Subject: [PATCH 1/9] Query category for disabled catalog with products returns the products count --- .../Model/Resolver/CategoryTree.php | 8 +++++++- .../Magento/GraphQl/Catalog/CategoryTest.php | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php index 1783a5cd9a7e5..866e002f1b43e 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php @@ -79,6 +79,12 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value } $result = $this->extractDataFromCategoryTree->execute($categoriesTree); - return current($result); + + $category = current($result); + if ($category['is_active'] == false) { + throw new GraphQlNoSuchEntityException(__('Category doesn\'t exist')); + } + + return $category; } } diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php index cbce53325e9e6..5fe46cdb19617 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php @@ -122,6 +122,25 @@ public function testGetCategoryById() self::assertEquals(13, $response['category']['id']); } + /** + * @magentoApiDataFixture Magento/Catalog/_files/categories.php + * @expectedException \Exception + * @expectedExceptionMessage Category doesn't exist + */ + public function testGetDisabledCategory() + { + $categoryId = 8; + $query = <<graphQlQuery($query); + } + public function testNonExistentCategoryWithProductCount() { $query = << Date: Tue, 16 Apr 2019 12:31:04 +0300 Subject: [PATCH 2/9] Query category for disabled catalog with products returns the products count --- .../CatalogGraphQl/Model/Resolver/CategoryTree.php | 8 +------- .../Products/DataProvider/ExtractDataFromCategoryTree.php | 5 +++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php index 866e002f1b43e..1783a5cd9a7e5 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php @@ -79,12 +79,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value } $result = $this->extractDataFromCategoryTree->execute($categoriesTree); - - $category = current($result); - if ($category['is_active'] == false) { - throw new GraphQlNoSuchEntityException(__('Category doesn\'t exist')); - } - - return $category; + return current($result); } } diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php index 3525ccbb6a2d1..cb0317e8dc975 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php @@ -9,6 +9,8 @@ use Magento\CatalogGraphQl\Model\Category\Hydrator; use Magento\Catalog\Api\Data\CategoryInterface; +use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; +use Magento\Catalog\Model\Category; /** * Extract data from category tree @@ -51,6 +53,9 @@ public function execute(\Iterator $iterator): array while ($iterator->valid()) { /** @var CategoryInterface $category */ $category = $iterator->current(); + if ($category->getIsActive() == false && $category->getId() != Category::TREE_ROOT_ID) { + throw new GraphQlNoSuchEntityException(__('Category doesn\'t exist')); + } $iterator->next(); $pathElements = explode("/", $category->getPath()); if (empty($tree)) { From e1aa92989eca4cb53206aa77c6442007a9e4b222 Mon Sep 17 00:00:00 2001 From: Ievgenii Gryshkun Date: Fri, 19 Apr 2019 09:45:21 +0300 Subject: [PATCH 3/9] Query category for disabled catalog with products returns the products count --- .../Products/DataProvider/CategoryTree.php | 28 +++++++++++++++++++ .../ExtractDataFromCategoryTree.php | 5 ---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php index fc5a563c82b4e..03fcc7fb35224 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php @@ -85,6 +85,9 @@ public function getTree(ResolveInfo $resolveInfo, int $rootCategoryId): \Iterato { $categoryQuery = $resolveInfo->fieldNodes[0]; $collection = $this->collectionFactory->create(); + if ($this->isRootCategoryActive($collection, $rootCategoryId) == false) { + throw new \Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException(__('Category doesn\'t exist')); + } $this->joinAttributesRecursively($collection, $categoryQuery); $depth = $this->depthCalculator->calculate($categoryQuery); $level = $this->levelCalculator->calculate($rootCategoryId); @@ -144,4 +147,29 @@ private function joinAttributesRecursively(Collection $collection, FieldNode $fi $this->joinAttributesRecursively($collection, $node); } } + + /** + * @param Collection $collection + * @param int $rootCategoryId + * + * @return bool + * @throws \Exception + */ + private function isRootCategoryActive(Collection $collection, int $rootCategoryId) : bool + { + if ($rootCategoryId == Category::TREE_ROOT_ID) { + return true; + } + $collection->addAttributeToFilter(Category::KEY_IS_ACTIVE, ['eq' => 1]) + ->getSelect() + ->where( + $collection->getSelect() + ->getConnection() + ->quoteIdentifier( + 'e.' . $this->metadata->getMetadata(CategoryInterface::class)->getIdentifierField() + ) . ' = ?', + $rootCategoryId + ); + return (bool) $collection->count(); + } } diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php index cb0317e8dc975..3525ccbb6a2d1 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php @@ -9,8 +9,6 @@ use Magento\CatalogGraphQl\Model\Category\Hydrator; use Magento\Catalog\Api\Data\CategoryInterface; -use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; -use Magento\Catalog\Model\Category; /** * Extract data from category tree @@ -53,9 +51,6 @@ public function execute(\Iterator $iterator): array while ($iterator->valid()) { /** @var CategoryInterface $category */ $category = $iterator->current(); - if ($category->getIsActive() == false && $category->getId() != Category::TREE_ROOT_ID) { - throw new GraphQlNoSuchEntityException(__('Category doesn\'t exist')); - } $iterator->next(); $pathElements = explode("/", $category->getPath()); if (empty($tree)) { From 8ca4590a01173908c1c5ff265954a13756d1c39d Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Wed, 24 Apr 2019 12:01:17 -0500 Subject: [PATCH 4/9] GraphQL-463: Query category for disabled catalog with products returns the products count --- .../Products/DataProvider/CategoryTree.php | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php index 03fcc7fb35224..0f305efa5f073 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php @@ -11,6 +11,7 @@ use Magento\CatalogGraphQl\Model\Category\DepthCalculator; use Magento\CatalogGraphQl\Model\Category\LevelCalculator; use Magento\Framework\EntityManager\MetadataPool; +use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Catalog\Api\Data\CategoryInterface; use Magento\Catalog\Model\ResourceModel\Category\Collection; @@ -84,10 +85,11 @@ public function __construct( public function getTree(ResolveInfo $resolveInfo, int $rootCategoryId): \Iterator { $categoryQuery = $resolveInfo->fieldNodes[0]; - $collection = $this->collectionFactory->create(); - if ($this->isRootCategoryActive($collection, $rootCategoryId) == false) { - throw new \Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException(__('Category doesn\'t exist')); + if ($this->isCategoryActive($rootCategoryId) == false) { + throw new GraphQlNoSuchEntityException(__('Category doesn\'t exist')); } + + $collection = $this->collectionFactory->create(); $this->joinAttributesRecursively($collection, $categoryQuery); $depth = $this->depthCalculator->calculate($categoryQuery); $level = $this->levelCalculator->calculate($rootCategoryId); @@ -149,27 +151,26 @@ private function joinAttributesRecursively(Collection $collection, FieldNode $fi } /** - * @param Collection $collection * @param int $rootCategoryId - * * @return bool * @throws \Exception */ - private function isRootCategoryActive(Collection $collection, int $rootCategoryId) : bool + private function isCategoryActive(int $rootCategoryId) : bool { if ($rootCategoryId == Category::TREE_ROOT_ID) { return true; } + $collection = $this->collectionFactory->create(); $collection->addAttributeToFilter(Category::KEY_IS_ACTIVE, ['eq' => 1]) ->getSelect() ->where( $collection->getSelect() - ->getConnection() - ->quoteIdentifier( - 'e.' . $this->metadata->getMetadata(CategoryInterface::class)->getIdentifierField() - ) . ' = ?', - $rootCategoryId + ->getConnection() + ->quoteIdentifier( + 'e.' . $this->metadata->getMetadata(CategoryInterface::class)->getIdentifierField() + ) . ' = ?', + $rootCategoryId ); - return (bool) $collection->count(); + return (bool)$collection->count(); } } From 201cdf2aa003e51f347d6c29043b37c0e18e8b1e Mon Sep 17 00:00:00 2001 From: Ievgenii Gryshkun Date: Sat, 27 Apr 2019 12:41:50 +0300 Subject: [PATCH 5/9] Query category for disabled catalog with products returns the product count #476 --- .../Model/Resolver/Products/DataProvider/CategoryTree.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php index 03fcc7fb35224..80653bfdeca86 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php @@ -149,6 +149,8 @@ private function joinAttributesRecursively(Collection $collection, FieldNode $fi } /** + * Check if provided category active + * * @param Collection $collection * @param int $rootCategoryId * From b676132f2a1c230fcb80ae7af5f52ef842b0959c Mon Sep 17 00:00:00 2001 From: Ievgenii Gryshkun Date: Fri, 10 May 2019 09:00:17 +0300 Subject: [PATCH 6/9] GraphQl-463: Query category for disabled catalog with products returns the product count --- .../Model/Resolver/Products/DataProvider/CategoryTree.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php index c930f5a0b3b1b..2fd48938af3cb 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php @@ -85,7 +85,7 @@ public function __construct( public function getTree(ResolveInfo $resolveInfo, int $rootCategoryId): \Iterator { $categoryQuery = $resolveInfo->fieldNodes[0]; - if ($this->isCategoryActive($rootCategoryId) == false) { + if ($this->isCategoryActive($rootCategoryId) === false) { throw new GraphQlNoSuchEntityException(__('Category doesn\'t exist')); } @@ -155,7 +155,7 @@ private function joinAttributesRecursively(Collection $collection, FieldNode $fi * * @param int $rootCategoryId * @return bool - * @throws \Exception + * @throws \Magento\Framework\Exception\LocalizedException */ private function isCategoryActive(int $rootCategoryId) : bool { From 525a1e9769c88c22ef47af80f235e2738935902a Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Fri, 21 Jun 2019 11:20:21 -0500 Subject: [PATCH 7/9] magento/graphql-ce#463: Query category for disabled catalog with products returns the products count --- .../Category/CheckCategoryIsActive.php | 67 +++++++++++++++++++ .../Model/Resolver/CategoryTree.php | 18 ++++- .../Products/DataProvider/CategoryTree.php | 31 --------- 3 files changed, 83 insertions(+), 33 deletions(-) create mode 100644 app/code/Magento/CatalogGraphQl/Model/Resolver/Category/CheckCategoryIsActive.php diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/CheckCategoryIsActive.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/CheckCategoryIsActive.php new file mode 100644 index 0000000000000..bf8057c63de39 --- /dev/null +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/CheckCategoryIsActive.php @@ -0,0 +1,67 @@ +collectionFactory = $collectionFactory; + $this->metadata = $metadata; + } + + /** + * Check if category is active. + * + * @param int $rootCategoryId + * @throws GraphQlNoSuchEntityException + */ + public function execute(int $rootCategoryId): void + { + $collection = $this->collectionFactory->create(); + $collection->addAttributeToFilter(Category::KEY_IS_ACTIVE, ['eq' => 1]) + ->getSelect() + ->where( + $collection->getSelect() + ->getConnection() + ->quoteIdentifier( + 'e.' . + $this->metadata->getMetadata(CategoryInterface::class)->getIdentifierField() + ) . ' = ?', + $rootCategoryId + ); + + if ($collection->count() === 0) { + throw new GraphQlNoSuchEntityException(__('Category doesn\'t exist')); + } + } +} diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php index 1783a5cd9a7e5..8d7aa5495b3ff 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php @@ -7,6 +7,8 @@ namespace Magento\CatalogGraphQl\Model\Resolver; +use Magento\Catalog\Model\Category; +use Magento\CatalogGraphQl\Model\Resolver\Category\CheckCategoryIsActive; use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\ExtractDataFromCategoryTree; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Framework\GraphQl\Config\Element\Field; @@ -34,16 +36,25 @@ class CategoryTree implements ResolverInterface */ private $extractDataFromCategoryTree; + /** + * @var CheckCategoryIsActive + */ + private $checkCategoryIsActive; + /** * @param \Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\CategoryTree $categoryTree * @param ExtractDataFromCategoryTree $extractDataFromCategoryTree + * @param CheckCategoryIsActive $checkCategoryIsActive */ public function __construct( \Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\CategoryTree $categoryTree, - ExtractDataFromCategoryTree $extractDataFromCategoryTree - ) { + ExtractDataFromCategoryTree $extractDataFromCategoryTree, + CheckCategoryIsActive $checkCategoryIsActive + ) + { $this->categoryTree = $categoryTree; $this->extractDataFromCategoryTree = $extractDataFromCategoryTree; + $this->checkCategoryIsActive = $checkCategoryIsActive; } /** @@ -72,6 +83,9 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value } $rootCategoryId = $this->getCategoryId($args); + if ($rootCategoryId !== Category::TREE_ROOT_ID) { + $this->checkCategoryIsActive->execute($rootCategoryId); + } $categoriesTree = $this->categoryTree->getTree($info, $rootCategoryId); if (empty($categoriesTree) || ($categoriesTree->count() == 0)) { diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php index 2fd48938af3cb..fc5a563c82b4e 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php @@ -11,7 +11,6 @@ use Magento\CatalogGraphQl\Model\Category\DepthCalculator; use Magento\CatalogGraphQl\Model\Category\LevelCalculator; use Magento\Framework\EntityManager\MetadataPool; -use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Catalog\Api\Data\CategoryInterface; use Magento\Catalog\Model\ResourceModel\Category\Collection; @@ -85,10 +84,6 @@ public function __construct( public function getTree(ResolveInfo $resolveInfo, int $rootCategoryId): \Iterator { $categoryQuery = $resolveInfo->fieldNodes[0]; - if ($this->isCategoryActive($rootCategoryId) === false) { - throw new GraphQlNoSuchEntityException(__('Category doesn\'t exist')); - } - $collection = $this->collectionFactory->create(); $this->joinAttributesRecursively($collection, $categoryQuery); $depth = $this->depthCalculator->calculate($categoryQuery); @@ -149,30 +144,4 @@ private function joinAttributesRecursively(Collection $collection, FieldNode $fi $this->joinAttributesRecursively($collection, $node); } } - - /** - * Check if provided category active - * - * @param int $rootCategoryId - * @return bool - * @throws \Magento\Framework\Exception\LocalizedException - */ - private function isCategoryActive(int $rootCategoryId) : bool - { - if ($rootCategoryId == Category::TREE_ROOT_ID) { - return true; - } - $collection = $this->collectionFactory->create(); - $collection->addAttributeToFilter(Category::KEY_IS_ACTIVE, ['eq' => 1]) - ->getSelect() - ->where( - $collection->getSelect() - ->getConnection() - ->quoteIdentifier( - 'e.' . $this->metadata->getMetadata(CategoryInterface::class)->getIdentifierField() - ) . ' = ?', - $rootCategoryId - ); - return (bool)$collection->count(); - } } From af968300a43925b865727d18b3e62a16cace8454 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Fri, 21 Jun 2019 11:38:39 -0500 Subject: [PATCH 8/9] magento/graphql-ce#463: Query category for disabled catalog with products returns the products count --- .../Model/Resolver/Category/CheckCategoryIsActive.php | 5 +++-- .../Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/CheckCategoryIsActive.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/CheckCategoryIsActive.php index bf8057c63de39..5903695d7a5eb 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/CheckCategoryIsActive.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/CheckCategoryIsActive.php @@ -3,6 +3,8 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\CatalogGraphQl\Model\Resolver\Category; use Magento\Catalog\Api\Data\CategoryInterface; @@ -33,8 +35,7 @@ class CheckCategoryIsActive public function __construct( CollectionFactory $collectionFactory, MetadataPool $metadata - ) - { + ) { $this->collectionFactory = $collectionFactory; $this->metadata = $metadata; } diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php index 8d7aa5495b3ff..89d3805383e1a 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php @@ -50,8 +50,7 @@ public function __construct( \Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\CategoryTree $categoryTree, ExtractDataFromCategoryTree $extractDataFromCategoryTree, CheckCategoryIsActive $checkCategoryIsActive - ) - { + ) { $this->categoryTree = $categoryTree; $this->extractDataFromCategoryTree = $extractDataFromCategoryTree; $this->checkCategoryIsActive = $checkCategoryIsActive; From 0b2bdc665ccd5326bae336ba5904116341b40b11 Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Fri, 21 Jun 2019 13:59:47 -0500 Subject: [PATCH 9/9] magento/graphql-ce#463: Query category for disabled catalog with products returns the products count --- .../Model/Resolver/Category/CheckCategoryIsActive.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/CheckCategoryIsActive.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/CheckCategoryIsActive.php index 5903695d7a5eb..16f816a967123 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/CheckCategoryIsActive.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Category/CheckCategoryIsActive.php @@ -8,7 +8,6 @@ namespace Magento\CatalogGraphQl\Model\Resolver\Category; use Magento\Catalog\Api\Data\CategoryInterface; -use Magento\Catalog\Model\Category; use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException; use Magento\Framework\EntityManager\MetadataPool; use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory; @@ -43,13 +42,13 @@ public function __construct( /** * Check if category is active. * - * @param int $rootCategoryId + * @param int $categoryId * @throws GraphQlNoSuchEntityException */ - public function execute(int $rootCategoryId): void + public function execute(int $categoryId): void { $collection = $this->collectionFactory->create(); - $collection->addAttributeToFilter(Category::KEY_IS_ACTIVE, ['eq' => 1]) + $collection->addAttributeToFilter(CategoryInterface::KEY_IS_ACTIVE, ['eq' => 1]) ->getSelect() ->where( $collection->getSelect() @@ -58,7 +57,7 @@ public function execute(int $rootCategoryId): void 'e.' . $this->metadata->getMetadata(CategoryInterface::class)->getIdentifierField() ) . ' = ?', - $rootCategoryId + $categoryId ); if ($collection->count() === 0) {