/** * Add specific filters * * @param Collection $collection * @return Collection */ protected function addCollectionFilters(Collection $collection) { $relatedProducts = []; /** @var ProductLinkInterface $linkItem */ foreach ($this->productLinkRepository->getList($this->getProduct()) as $linkItem) { if ($linkItem->getLinkType() !== $this->getLinkType()) { continue; } $relatedProducts[] = $this->productRepository->get($linkItem->getLinkedProductSku())->getId(); } if ($relatedProducts) { $collection->addAttributeToFilter($collection->getIdFieldName(), ['nin' => [$relatedProducts]]); } return $collection; }