Skip to content

Commit 7b1c4dd

Browse files
committed
fix regexp when category being filtered is root category
1 parent 6b7a9b3 commit 7b1c4dd

File tree

1 file changed

+10
-1
lines changed
  • app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,17 @@ public function getTree(ResolveInfo $resolveInfo, int $rootCategoryId) : array
9494
$this->joinAttributesRecursively($collection, $categoryQuery);
9595
$depth = $this->depthCalculator->calculate($categoryQuery);
9696
$level = $this->levelCalculator->calculate($rootCategoryId);
97+
98+
// If root category is being filter, we've to remove first slash
99+
if($rootCategoryId == 1) {
100+
$regExpPathFilter = sprintf('.*%s/[/0-9]*$', $rootCategoryId);
101+
} else {
102+
$regExpPathFilter = sprintf('.*/%s/[/0-9]*$', $rootCategoryId);
103+
}
104+
97105
//Search for desired part of category tree
98-
$collection->addPathFilter(sprintf('.*/%s/[/0-9]*$', $rootCategoryId));
106+
$collection->addPathFilter($regExpPathFilter);
107+
99108
$collection->addFieldToFilter('level', ['gt' => $level]);
100109
$collection->addFieldToFilter('level', ['lteq' => $level + $depth - self::DEPTH_OFFSET]);
101110
$collection->setOrder('level');

0 commit comments

Comments
 (0)