Skip to content

Commit 12dcafa

Browse files
committed
Merge branch 'MC-43010' of https://github.com/magento-l3/magento2ce into PR-2021-08-18
2 parents 44dcacf + 42c0fd7 commit 12dcafa

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function execute(\Iterator $iterator): array
6464
if (empty($tree)) {
6565
$tree = $currentLevelTree;
6666
}
67-
$tree = $this->mergeCategoriesTrees($currentLevelTree, $tree);
67+
$tree = $this->mergeCategoriesTrees($tree, $currentLevelTree);
6868
}
6969
}
7070

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,38 @@ public function testCategoriesTree()
132132
);
133133
}
134134

135+
/**
136+
* @magentoApiDataFixture Magento/Catalog/_files/category_with_parent_anchor.php
137+
*/
138+
public function testCategoryTree()
139+
{
140+
$rootCategoryId = 2;
141+
$query = <<<QUERY
142+
{
143+
category(id: {$rootCategoryId}) {
144+
children {
145+
id
146+
name
147+
children {
148+
id
149+
name
150+
}
151+
}
152+
}
153+
}
154+
QUERY;
155+
$response = $this->graphQlQuery($query);
156+
$responseDataObject = new DataObject($response);
157+
self::assertEquals(
158+
'Parent category',
159+
$responseDataObject->getData('category/children/0/name')
160+
);
161+
self::assertEquals(
162+
'Child category',
163+
$responseDataObject->getData('category/children/0/children/0/name')
164+
);
165+
}
166+
135167
/**
136168
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
137169
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)

dev/tests/integration/testsuite/Magento/Catalog/_files/category_with_parent_anchor.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@
2727
'is_anchor' => true,
2828
];
2929
$parentCategory->setData($parentCategoryData);
30-
$parentCategoryId = $categoryRepository->save($parentCategory)->getId();
30+
$parentCategory = $categoryRepository->save($parentCategory);
3131

3232
$category = $categoryFactory->create();
3333
$category->isObjectNew(true);
3434
$categoryData = [
3535
'name' => 'Child category',
3636
'attribute_set_id' => $attributeSetId,
37-
'parent_id' => $parentCategoryId,
37+
'parent_id' => $parentCategory->getId(),
3838
'is_active' => true,
3939
];
4040
$category->setData($categoryData);
4141
$categoryRepository->save($category);
42+
43+
//save parent category to set "children" attribute
44+
$categoryRepository->save($parentCategory);

0 commit comments

Comments
 (0)