Skip to content

Commit

Permalink
Clean database criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasGraml11 committed Apr 29, 2024
1 parent f3ff43e commit a42a56e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Traits/SearchResultHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ protected function fetchProducts(
SalesChannelContext $salesChannelContext,
?string $query = null
): EntitySearchResult {
$productCriteria = clone $criteria;
$productCriteria = $this->cleanDatabaseCriteria($criteria);

if ($query !== null && count($productCriteria->getIds()) === 1) {
$this->modifyCriteriaFromQuery($query, $productCriteria, $salesChannelContext);
}

$productCriteria->resetAggregations();

$result = $this->salesChannelProductRepository->search($productCriteria, $salesChannelContext);

return $this->fixResultOrder($result, $productCriteria);
Expand Down Expand Up @@ -147,4 +146,16 @@ private function modifyCriteriaFromQuery(
$criteria->setIds([$product->getId()]);
}
}

private function cleanDatabaseCriteria(Criteria $criteria): Criteria
{
$productCriteria = clone $criteria;
$productCriteria->setOffset(0);
$productCriteria->resetQueries();
$productCriteria->resetFilters();
$productCriteria->resetSorting();
$productCriteria->resetAggregations();

return $productCriteria;
}
}

0 comments on commit a42a56e

Please sign in to comment.