Skip to content

Commit

Permalink
Merge branch '2.10.x' into 2.11.x
Browse files Browse the repository at this point in the history
  • Loading branch information
romainruaud committed May 2, 2024
2 parents f8eb389 + 6b7c0e9 commit 8c17f0a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/module-elasticsuite-virtual-category/Model/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,14 @@ public function __toString(): string
* do not use the $excludedCategories parameters to check if the category rule has been calculated, but use the local cache.
* @codingStandardsIgnoreEnd
* @SuppressWarnings(PHPMD.StaticAccess)
* @SuppressWarnings(PHPMD.NPathComplexity)
*
* @return QueryInterface|null
*/
public function getCategorySearchQuery($category, $excludedCategories = []): ?QueryInterface
{
\Magento\Framework\Profiler::start('ES:Virtual Rule ' . __FUNCTION__);
$categoryId = (int) !is_object($category) ? $category : $category->getId();
$categoryId = (int) (!is_object($category) ? $category : $category->getId());
$cacheKey = implode(
'|',
[
Expand All @@ -204,13 +205,16 @@ public function getCategorySearchQuery($category, $excludedCategories = []): ?Qu
}
$query = $this->buildCategorySearchQuery($category, $excludedCategories);

if (!$category->getHasDraftVirtualRule() && $query !== null) {
if (!$category->getHasDraftVirtualRule() && $query !== null && !in_array($categoryId, $excludedCategories)) {
$cacheData = serialize($query);
$this->sharedCache->save($cacheData, $cacheKey, $category->getCacheTags());
}
}

$this->saveInLocalCache($categoryId, $query);
if (!in_array($categoryId, $excludedCategories)) {
$this->saveInLocalCache($categoryId, $query);
}

\Magento\Framework\Profiler::stop('ES:Virtual Rule ' . __FUNCTION__);

return $query;
Expand Down Expand Up @@ -416,16 +420,16 @@ private function getVirtualCategoryQuery(
CategoryInterface $category,
$excludedCategories = []
): ?QueryInterface {
$query = $category->getVirtualRule()->getConditions()->getSearchQuery($excludedCategories);
$rootCategory = $this->getVirtualRootCategory($category);

if ($rootCategory && in_array($rootCategory->getId(), $excludedCategories)) {
$query = null;
return null;
}

$query = $category->getVirtualRule()->getConditions()->getSearchQuery($excludedCategories);
if ($rootCategory && $rootCategory->getId()) {
$rootQuery = $this->getCategorySearchQuery($rootCategory, $excludedCategories);
if ($rootQuery) {
$query = $this->queryFactory->create(QueryInterface::TYPE_BOOL, ['must' => [$query, $rootQuery]]);
$query = $this->queryFactory->create(QueryInterface::TYPE_BOOL, ['must' => array_filter([$query, $rootQuery])]);
}
}

Expand Down

0 comments on commit 8c17f0a

Please sign in to comment.