This repository has been archived by the owner on Dec 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 156
[BugFix] Graph Ql category tree structure is lost (children all grouped with last item) #246
Comments
Fix with tests for this issue has been prepared and will be uploaded for code review and pull request soon. |
naydav
changed the title
Graph Ql category tree structure is lost (children all grouped with last item)
[BugFix] Graph Ql category tree structure is lost (children all grouped with last item)
Dec 12, 2018
Ran into this as well. We're currently using the following diff to work around it for now: diff --git a/Model/Resolver/Products/DataProvider/CategoryTree.php b/Model/Resolver/Products/DataProvider/CategoryTree.php
index bae9def4ee6..8201c6d7819 100644
--- a/Model/Resolver/Products/DataProvider/CategoryTree.php
+++ b/Model/Resolver/Products/DataProvider/CategoryTree.php
@@ -98,29 +98,33 @@ class CategoryTree
$collection->addPathFilter(sprintf('.*/%s/[/0-9]*$', $rootCategoryId));
$collection->addFieldToFilter('level', ['gt' => $level]);
$collection->addFieldToFilter('level', ['lteq' => $level + $depth - self::DEPTH_OFFSET]);
- $collection->setOrder('level');
+ $collection->setOrder('path');
$collection->getSelect()->orWhere(
$this->metadata->getMetadata(CategoryInterface::class)->getIdentifierField() . ' = ?',
$rootCategoryId
);
- return $this->processTree($collection->getIterator());
+ return $this->processTree($collection->getIterator(), $level);
}
/**
* @param \Iterator $iterator
* @return array
*/
- private function processTree(\Iterator $iterator) : array
+ private function processTree(\Iterator $iterator, $currentLevel) : array
{
$tree = [];
while ($iterator->valid()) {
/** @var CategoryInterface $category */
$category = $iterator->current();
+ if ($currentLevel > $category->getLevel()) {
+ break;
+ }
$iterator->next();
$nextCategory = $iterator->current();
$tree[$category->getId()] = $this->hydrator->hydrateCategory($category);
- if ($nextCategory && (int) $nextCategory->getLevel() !== (int) $category->getLevel()) {
- $tree[$category->getId()]['children'] = $this->processTree($iterator);
+ if ($nextCategory && $nextCategory->getLevel() > $category->getLevel()) {
+ $tree[$nextCategory->getParentId()]['children'] =
+ $this->processTree($iterator, $nextCategory->getLevel());
}
} Probably not the most elegant way, and also 2.3-develop has refactored many parts and this diff applies on 2.3.0 only. Looking forward to a "proper" patch :) |
It was fixed within this PR and merged |
Glad to hear this was fixed |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Preconditions
Magento 2.3-develop
Steps to reproduce
Run the following Graph Ql query
Expected result
Category tree with categories and their children. Tree matches site category structure
Actual result
Categories are sorted according to their levels where last items get all the children.
The text was updated successfully, but these errors were encountered: