Skip to content

Commit

Permalink
Enabling exclusion of identifiersProductId from elastic search aggreg…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
christopherhero committed Oct 24, 2024
1 parent 6ebb13f commit ffec3ba
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Finder/RelatedProductsByOrderHistoryFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function findRelatedByChannelAndSlug(
throw new ProductNotFoundException($slug, $channel, $locale);
}

return $this->getRelatedByOrderHistory($product->getId(), $channel, $maxResults);
return $this->getRelatedByOrderHistory($product->getId(), $channel, $maxResults, $excludedProductIds);
}

/**
Expand All @@ -65,14 +65,14 @@ protected function getRelatedByOrderHistory(
int $productId,
ChannelInterface $channel,
int $maxResults,
array $excludedProductIds = []
): array {
$products = $this->relatedProductsFinder->findPaginated(
$this->queryBuilder->buildQuery($productId),
);
$products = $this->relatedProductsFinder->findPaginated($this->queryBuilder->buildQuery($productId));
$excludedProductIds[] = $productId;

return $this->productRepository->findManyByChannelAndIds(
$channel,
$this->extractProductIds($products, $productId),
$this->extractProductIds($products, $excludedProductIds),
$maxResults,
);
}
Expand All @@ -82,7 +82,7 @@ protected function getRelatedByOrderHistory(
*
* @param Pagerfanta<mixed> $result
*/
protected function extractProductIds(Pagerfanta $result, int $excludeId): array
protected function extractProductIds(Pagerfanta $result, array $excludedProductIds = []): array
{
$result->setMaxPerPage(1);
$result->setCurrentPage(1);
Expand All @@ -97,7 +97,7 @@ protected function extractProductIds(Pagerfanta $result, int $excludeId): array
$productIds = [];
foreach ($aggregation['buckets'] as $bucket) {
$id = $bucket['key'];
if ($id === $excludeId) {
if (in_array($id, $excludedProductIds, true)) {
continue;
}

Expand Down

0 comments on commit ffec3ba

Please sign in to comment.