<?php declare(strict_types=1);
namespace Swag\EnterpriseSearch\Boosting;
use Shopware\Core\Framework\Api\Context\SalesChannelApiSource;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
class BoostingProvider
{
/**
* @var BoostingRepository
*/
private $boostingRepository;
/**
* @var ResolverRegistry
*/
private $resolverRegistry;
public function __construct(
BoostingRepository $boostingRepository,
ResolverRegistry $resolverRegistry
) {
$this->boostingRepository = $boostingRepository;
$this->resolverRegistry = $resolverRegistry;
}
public function getActiveBoostings(EntityDefinition $definition, Context $context): array
{
$contextSource = $context->getSource();
if (!$contextSource instanceof SalesChannelApiSource) {
return [];
}
$streamResolver = $this->resolverRegistry->getResolver($definition);
$boostingCollection = $this->boostingRepository->getBoostings(
$definition,
$context,
$contextSource,
$streamResolver->getType()
);
return $streamResolver->createBoostingCombination($boostingCollection, $context);
}
public function getActiveBoostingsBySalesChannelIds(EntityDefinition $definition, Context $context, array $salesChannelIds): array
{
$contextSource = $context->getSource();
if (!$contextSource instanceof SalesChannelApiSource) {
return [];
}
$streamResolver = $this->resolverRegistry->getResolver($definition);
$boostingCollection = $this->boostingRepository->getBoostingsBySalesChannelids(
$definition,
$context,
$salesChannelIds,
$streamResolver->getType()
);
return $streamResolver->createBoostingCombination($boostingCollection, $context);
}
}