vendor/shopware/core/Content/Product/SalesChannel/Review/ProductReviewRoute.php line 47

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Product\SalesChannel\Review;
  3. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\MultiFilter;
  7. use Shopware\Core\Framework\Log\Package;
  8. use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException;
  9. use Shopware\Core\Framework\Routing\Annotation\Entity;
  10. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  11. use Shopware\Core\Framework\Routing\Annotation\Since;
  12. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. /**
  16.  * @Route(defaults={"_routeScope"={"store-api"}})
  17.  */
  18. #[Package('inventory')]
  19. class ProductReviewRoute extends AbstractProductReviewRoute
  20. {
  21.     /**
  22.      * @var EntityRepositoryInterface
  23.      */
  24.     private $repository;
  25.     /**
  26.      * @internal
  27.      */
  28.     public function __construct(EntityRepositoryInterface $repository)
  29.     {
  30.         $this->repository $repository;
  31.     }
  32.     public function getDecorated(): AbstractProductReviewRoute
  33.     {
  34.         throw new DecorationPatternException(self::class);
  35.     }
  36.     /**
  37.      * @Since("6.3.2.0")
  38.      * @Entity("product_review")
  39.      * @Route("/store-api/product/{productId}/reviews", name="store-api.product-review.list", methods={"POST"})
  40.      */
  41.     public function load(string $productIdRequest $requestSalesChannelContext $contextCriteria $criteria): ProductReviewRouteResponse
  42.     {
  43.         $active = new MultiFilter(MultiFilter::CONNECTION_OR, [new EqualsFilter('status'true)]);
  44.         if ($customer $context->getCustomer()) {
  45.             $active->addQuery(new EqualsFilter('customerId'$customer->getId()));
  46.         }
  47.         $criteria->setTitle('product-review-route');
  48.         $criteria->addFilter(
  49.             new MultiFilter(MultiFilter::CONNECTION_AND, [
  50.                 $active,
  51.                 new MultiFilter(MultiFilter::CONNECTION_OR, [
  52.                     new EqualsFilter('product.id'$productId),
  53.                     new EqualsFilter('product.parentId'$productId),
  54.                 ]),
  55.             ])
  56.         );
  57.         $result $this->repository->search($criteria$context->getContext());
  58.         return new ProductReviewRouteResponse($result);
  59.     }
  60. }