Skip to content

Commit 28e89b7

Browse files
committed
Merge remote-tracking branch 'eduard13/graphql-breadcrumbs-30468-issue' into HB-PR-delivery-Oct
2 parents 1f8d588 + 51b24f4 commit 28e89b7

File tree

2 files changed

+41
-0
lines changed
  • app/code/Magento/CatalogGraphQl/Model/Resolver/Category/DataProvider
  • dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog

2 files changed

+41
-0
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Category/DataProvider/Breadcrumbs.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\CatalogGraphQl\Model\Resolver\Category\DataProvider;
99

10+
use Magento\Catalog\Api\Data\CategoryInterface;
1011
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
1112

1213
/**
@@ -46,6 +47,7 @@ public function getData(string $categoryPath): array
4647
$collection = $this->collectionFactory->create();
4748
$collection->addAttributeToSelect(['name', 'url_key', 'url_path']);
4849
$collection->addAttributeToFilter('entity_id', $parentCategoryIds);
50+
$collection->addAttributeToFilter(CategoryInterface::KEY_IS_ACTIVE, 1);
4951

5052
foreach ($collection as $category) {
5153
$breadcrumbsData[] = [

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,45 @@ public function testCategoryImage(?string $imagePrefix)
660660
$this->assertEquals($expectedImageUrl, $childCategory['image']);
661661
}
662662

663+
/**
664+
* Testing breadcrumbs that shouldn't include disabled parent categories
665+
*
666+
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
667+
*/
668+
public function testBreadCrumbsWithDisabledParentCategory()
669+
{
670+
$parentCategoryId = 4;
671+
$childCategoryId = 5;
672+
$category = $this->categoryRepository->get($parentCategoryId);
673+
$category->setIsActive(false);
674+
$this->categoryRepository->save($category);
675+
676+
$query = <<<QUERY
677+
{
678+
category(id: {$childCategoryId}) {
679+
name
680+
breadcrumbs {
681+
category_id
682+
category_name
683+
}
684+
}
685+
}
686+
QUERY;
687+
$response = $this->graphQlQuery($query);
688+
$expectedResponse = [
689+
'category' => [
690+
'name' => 'Category 1.1.1',
691+
'breadcrumbs' => [
692+
[
693+
'category_id' => 3,
694+
'category_name' => "Category 1",
695+
]
696+
]
697+
]
698+
];
699+
$this->assertEquals($expectedResponse, $response);
700+
}
701+
663702
/**
664703
* @return array
665704
*/

0 commit comments

Comments
 (0)