<?php declare(strict_types=1);
namespace Shopware\Core\Content\Product\Cart;
use Shopware\Core\Content\Product\Events\ProductGatewayCriteriaEvent;
use Shopware\Core\Content\Product\ProductCollection;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
class ProductGateway implements ProductGatewayInterface
{
/**
* @var SalesChannelRepositoryInterface
*/
private $repository;
/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;
/**
* @internal
*/
public function __construct(
SalesChannelRepositoryInterface $repository,
EventDispatcherInterface $eventDispatcher
) {
$this->repository = $repository;
$this->eventDispatcher = $eventDispatcher;
}
public function get(array $ids, SalesChannelContext $context): ProductCollection
{
$criteria = new Criteria($ids);
$criteria->setTitle('cart::products');
$criteria->addAssociation('cover');
$criteria->addAssociation('options.group');
$criteria->addAssociation('featureSet');
$criteria->addAssociation('properties.group');
$this->eventDispatcher->dispatch(
new ProductGatewayCriteriaEvent($ids, $criteria, $context)
);
/** @var ProductCollection $result */
$result = $this->repository->search($criteria, $context)->getEntities();
return $result;
}
}