<?php declare(strict_types=1);
namespace Shopware\Core\Content\Product\SalesChannel\Review;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\MultiFilter;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException;
use Shopware\Core\Framework\Routing\Annotation\Entity;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Shopware\Core\Framework\Routing\Annotation\Since;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route(defaults={"_routeScope"={"store-api"}})
*/
#[Package('inventory')]
class ProductReviewRoute extends AbstractProductReviewRoute
{
/**
* @var EntityRepositoryInterface
*/
private $repository;
/**
* @internal
*/
public function __construct(EntityRepositoryInterface $repository)
{
$this->repository = $repository;
}
public function getDecorated(): AbstractProductReviewRoute
{
throw new DecorationPatternException(self::class);
}
/**
* @Since("6.3.2.0")
* @Entity("product_review")
* @Route("/store-api/product/{productId}/reviews", name="store-api.product-review.list", methods={"POST"})
*/
public function load(string $productId, Request $request, SalesChannelContext $context, Criteria $criteria): ProductReviewRouteResponse
{
$active = new MultiFilter(MultiFilter::CONNECTION_OR, [new EqualsFilter('status', true)]);
if ($customer = $context->getCustomer()) {
$active->addQuery(new EqualsFilter('customerId', $customer->getId()));
}
$criteria->setTitle('product-review-route');
$criteria->addFilter(
new MultiFilter(MultiFilter::CONNECTION_AND, [
$active,
new MultiFilter(MultiFilter::CONNECTION_OR, [
new EqualsFilter('product.id', $productId),
new EqualsFilter('product.parentId', $productId),
]),
])
);
$result = $this->repository->search($criteria, $context->getContext());
return new ProductReviewRouteResponse($result);
}
}