Skip to content

Commit 8441cf4

Browse files
authored
Merge pull request #4827 from magento-honey-badgers/MC-20255
[honey] MC-20255: Category Breadcrumbs are missing url_path
2 parents 3490d3b + 71bf565 commit 8441cf4

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ public function __construct(
2929
}
3030

3131
/**
32+
* Get breadcrumbs data
33+
*
3234
* @param string $categoryPath
3335
* @return array
36+
* @throws \Magento\Framework\Exception\LocalizedException
3437
*/
3538
public function getData(string $categoryPath): array
3639
{
@@ -41,7 +44,7 @@ public function getData(string $categoryPath): array
4144

4245
if (count($parentCategoryIds)) {
4346
$collection = $this->collectionFactory->create();
44-
$collection->addAttributeToSelect(['name', 'url_key']);
47+
$collection->addAttributeToSelect(['name', 'url_key', 'url_path']);
4548
$collection->addAttributeToFilter('entity_id', $parentCategoryIds);
4649

4750
foreach ($collection as $category) {
@@ -50,6 +53,7 @@ public function getData(string $categoryPath): array
5053
'category_name' => $category->getName(),
5154
'category_level' => $category->getLevel(),
5255
'category_url_key' => $category->getUrlKey(),
56+
'category_url_path' => $category->getUrlPath(),
5357
];
5458
}
5559
}

app/code/Magento/CatalogGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ type Breadcrumb @doc(description: "Breadcrumb item."){
223223
category_name: String @doc(description: "Category name.")
224224
category_level: Int @doc(description: "Category level.")
225225
category_url_key: String @doc(description: "Category URL key.")
226+
category_url_path: String @doc(description: "Category URL path.")
226227
}
227228

228229
type CustomizableRadioOption implements CustomizableOptionInterface @doc(description: "CustomizableRadioOption contains information about a set of radio buttons that are defined as part of a customizable option.") {

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,57 @@ public function testAnchorCategory()
502502
$this->assertEquals($expectedResponse, $response);
503503
}
504504

505+
/**
506+
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
507+
*/
508+
public function testBreadCrumbs()
509+
{
510+
/** @var CategoryCollection $categoryCollection */
511+
$categoryCollection = $this->objectManager->create(CategoryCollection::class);
512+
$categoryCollection->addFieldToFilter('name', 'Category 1.1.1');
513+
/** @var CategoryInterface $category */
514+
$category = $categoryCollection->getFirstItem();
515+
$categoryId = $category->getId();
516+
$this->assertNotEmpty($categoryId, "Preconditions failed: category is not available.");
517+
$query = <<<QUERY
518+
{
519+
category(id: {$categoryId}) {
520+
name
521+
breadcrumbs {
522+
category_id
523+
category_name
524+
category_level
525+
category_url_key
526+
category_url_path
527+
}
528+
}
529+
}
530+
QUERY;
531+
$response = $this->graphQlQuery($query);
532+
$expectedResponse = [
533+
'category' => [
534+
'name' => 'Category 1.1.1',
535+
'breadcrumbs' => [
536+
[
537+
'category_id' => 3,
538+
'category_name' => "Category 1",
539+
'category_level' => 2,
540+
'category_url_key' => "category-1",
541+
'category_url_path' => "category-1"
542+
],
543+
[
544+
'category_id' => 4,
545+
'category_name' => "Category 1.1",
546+
'category_level' => 3,
547+
'category_url_key' => "category-1-1",
548+
'category_url_path' => "category-1/category-1-1"
549+
],
550+
]
551+
]
552+
];
553+
$this->assertEquals($expectedResponse, $response);
554+
}
555+
505556
/**
506557
* @param ProductInterface $product
507558
* @param array $actualResponse

0 commit comments

Comments
 (0)