Skip to content

Commit

Permalink
[PageBuilder] Fix #3493, apply a negation to the category_ids condition
Browse files Browse the repository at this point in the history
  • Loading branch information
vahonc committed Jan 27, 2025
1 parent 15fa726 commit b6b016d
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 b6b016d

Please sign in to comment.