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 da457279728bb..d2fc174fb1ed5 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php @@ -100,7 +100,7 @@ public function getTree(ResolveInfo $resolveInfo, int $rootCategoryId) : array $collection->addFieldToFilter('level', ['lteq' => $level + $depth - self::DEPTH_OFFSET]); $collection->setOrder('level'); $collection->getSelect()->orWhere( - $this->metadata->getMetadata(CategoryInterface::class)->getLinkField() . ' = ?', + $this->metadata->getMetadata(CategoryInterface::class)->getIdentifierField() . ' = ?', $rootCategoryId ); return $this->processTree($collection->getIterator()); 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 4f68090657a10..c7697a99875be 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php @@ -8,6 +8,7 @@ namespace Magento\GraphQl\Catalog; use Magento\Catalog\Api\Data\CategoryInterface; +use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection; use Magento\Framework\DataObject; use Magento\TestFramework\TestCase\GraphQlAbstract; use Magento\Catalog\Api\Data\ProductInterface; @@ -283,16 +284,13 @@ public function testCategoryProducts() */ public function testAnchorCategory() { - /** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $categoryCollection */ - $categoryCollection = $this->objectManager->create( - \Magento\Catalog\Model\ResourceModel\Category\Collection::class - ); + /** @var CategoryCollection $categoryCollection */ + $categoryCollection = $this->objectManager->create(CategoryCollection::class); $categoryCollection->addFieldToFilter('name', 'Category 1'); + /** @var CategoryInterface $category */ $category = $categoryCollection->getFirstItem(); - /** @var \Magento\Framework\EntityManager\MetadataPool $entityManagerMetadataPool */ - $entityManagerMetadataPool = $this->objectManager->create(\Magento\Framework\EntityManager\MetadataPool::class); - $categoryLinkField = $entityManagerMetadataPool->getMetadata(CategoryInterface::class)->getLinkField(); - $categoryId = $category->getData($categoryLinkField); + $categoryId = $category->getId(); + $this->assertNotEmpty($categoryId, "Preconditions failed: category is not available."); $query = <<