Skip to content

Commit

Permalink
Merge pull request Smile-SA#3501 from vahonc/3493-elasticsuite-page-b…
Browse files Browse the repository at this point in the history
…uilder-apply-negation-to-category-condition-2.10-fix

[PageBuilder] Fix Smile-SA#3493, apply a negation to the category_ids condition
  • Loading branch information
rbayet authored Jan 27, 2025
2 parents b69a37d + b6b016d commit 6d64013
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ public function afterCreateCollection(ProductsList $subject, $collection)
}
if (!empty($filterQueries)) {
$query = $this->queryFactory->create(QueryInterface::TYPE_BOOL, ['should' => $filterQueries]);

if (substr($condition['operator'], 0, 1) === '!') {
$query = $this->applyNegation($query);
}

$collection->addQueryFilter($query);
}
}
Expand Down Expand Up @@ -205,4 +210,29 @@ private function getCurrentStoreId(ProductsList $subject)

return $storeId;
}

/**
* Instantiate query from type and params.
*
* @param string $queryType Query type.
* @param array $queryParams Query instantiation params.
*
* @return QueryInterface
*/
private function prepareQuery($queryType, $queryParams)
{
return $this->queryFactory->create($queryType, $queryParams);
}

/**
* Apply a negation to the current query.
*
* @param QueryInterface $query Negated query.
*
* @return QueryInterface
*/
private function applyNegation(QueryInterface $query)
{
return $this->prepareQuery(QueryInterface::TYPE_NOT, ['query' => $query]);
}
}

0 comments on commit 6d64013

Please sign in to comment.