Skip to content

Commit

Permalink
Merge pull request #3280 from rbayet/feat-virtual-categories-debuggin…
Browse files Browse the repository at this point in the history
…g-2.10.x

[VirtualCategories] Making virtual categories queries named for debugging purposes
  • Loading branch information
romainruaud authored Jul 12, 2024
2 parents 7297a98 + 9dbce63 commit fa61b9b
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions src/module-elasticsuite-virtual-category/Model/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,10 @@ private function getRootCategory(int $rootCategoryId, int $storeId = null)
*/
private function getStandardCategoryQuery(CategoryInterface $category, $excludedCategories = []): QueryInterface
{
return $this->getStandardCategoriesQuery([$category->getId()], $excludedCategories);
$query = $this->getStandardCategoriesQuery([$category->getId()], $excludedCategories);
$query->setName(sprintf('(%s) standard category [%s]:%d', $category->getPath(), $category->getName(), $category->getId()));

return $query;
}

/**
Expand Down Expand Up @@ -426,10 +429,21 @@ private function getVirtualCategoryQuery(
}

$query = $category->getVirtualRule()->getConditions()->getSearchQuery($excludedCategories);
if ($query instanceof QueryInterface) {
$query->setName(sprintf('(%s) virtual category [%s]:%d', $category->getPath(), $category->getName(), $category->getId()));
}
if ($rootCategory && $rootCategory->getId()) {
$rootQuery = $this->getCategorySearchQuery($rootCategory, $excludedCategories);
if ($rootQuery) {
$query = $this->queryFactory->create(QueryInterface::TYPE_BOOL, ['must' => array_filter([$query, $rootQuery])]);
$query->setName(
sprintf(
'(%s) virtual category [%s]:%d and its virtual root',
$category->getPath(),
$category->getName(),
$category->getId()
)
);
}
}

Expand Down Expand Up @@ -459,6 +473,14 @@ private function addChildrenQueries($query, CategoryInterface $category, $exclud
if (((bool) $childrenCategory->getIsVirtualCategory()) === true) {
$childrenQuery = $this->getCategorySearchQuery($childrenCategory, $excludedCategories);
if ($childrenQuery !== null) {
$childrenQuery->setName(
sprintf(
'(%s) child virtual category [%s]:%d',
$childrenCategory->getPath(),
$childrenCategory->getName(),
$childrenCategory->getId()
)
);
$queryParams['should'][] = $childrenQuery;
}
} else {
Expand All @@ -467,11 +489,29 @@ private function addChildrenQueries($query, CategoryInterface $category, $exclud
}

if (!empty($childrenCategoriesIds)) {
$queryParams['should'][] = $this->getStandardCategoriesQuery($childrenCategoriesIds, $excludedCategories);
$standardChildrenQuery = $this->getStandardCategoriesQuery($childrenCategoriesIds, $excludedCategories);
$standardChildrenQuery->setName(
sprintf(
'(%s) standard children of virtual category [%s]:%d',
$category->getPath(),
$category->getName(),
$category->getId()
)
);

$queryParams['should'][] = $standardChildrenQuery;
}

if (count($queryParams['should']) > 1) {
$query = $this->queryFactory->create(QueryInterface::TYPE_BOOL, $queryParams);
$query->setName(
sprintf(
'(%s) category [%s]:%d and its children',
$category->getPath(),
$category->getName(),
$category->getId()
)
);
}
}

Expand Down Expand Up @@ -501,7 +541,7 @@ private function getChildrenCategories(CategoryInterface $category, $excludedCat
$categoryCollection->addAttributeToFilter('entity_id', ['nin' => $excludedCategories]);
}

$categoryCollection->addAttributeToSelect(['is_active', 'virtual_category_root', 'is_virtual_category', 'virtual_rule']);
$categoryCollection->addAttributeToSelect(['name', 'is_active', 'virtual_category_root', 'is_virtual_category', 'virtual_rule']);

return $categoryCollection;
}
Expand Down

0 comments on commit fa61b9b

Please sign in to comment.