Skip to content

Commit 053b7f3

Browse files
committed
B2B-2464: Improve category children loading
- Add exclude list for buildOutputDataArray
1 parent 6caac74 commit 053b7f3

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

app/code/Magento/CatalogGraphQl/Model/Category/Hydrator.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,19 @@ public function __construct(
5757
*/
5858
public function hydrateCategory(Category $category, $basicFieldsOnly = false) : array
5959
{
60-
if (!$basicFieldsOnly) {
61-
// initialize custom attributes (to be consequently included in subsequent getData call below)
62-
$category->getCustomAttributes();
60+
if ($basicFieldsOnly) {
61+
$categoryData = $category->getData();
62+
} else {
63+
$categoryData = $this->dataObjectProcessor->buildOutputDataArray(
64+
$category,
65+
CategoryInterface::class,
66+
[
67+
'getChildren',
68+
'getExtensionAttributes',
69+
]
70+
);
6371
}
6472

65-
$categoryData = $category->getData();
66-
6773
$categoryData['id'] = $category->getId();
6874
$categoryData['uid'] = $this->uidEncoder->encode((string) $category->getId());
6975
$categoryData['children'] = [];

lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,21 @@ public function __construct(
7575
*
7676
* @param mixed $dataObject
7777
* @param string $dataObjectType
78+
* @param array $excludedMethods - list of methods to exclude from being called
7879
* @return array
7980
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
8081
* @SuppressWarnings(PHPMD.NPathComplexity)
8182
*/
82-
public function buildOutputDataArray($dataObject, $dataObjectType)
83+
public function buildOutputDataArray($dataObject, $dataObjectType, array $excludedMethods = [])
8384
{
8485
$methods = $this->methodsMapProcessor->getMethodsMap($dataObjectType);
8586
$outputData = [];
8687

8788
foreach (array_keys($methods) as $methodName) {
89+
if (in_array($methodName, $excludedMethods)) {
90+
continue;
91+
}
92+
8893
if (!$this->methodsMapProcessor->isMethodValidForDataField($dataObjectType, $methodName)) {
8994
continue;
9095
}

0 commit comments

Comments
 (0)