vendor/shopware/core/Content/LandingPage/SalesChannel/LandingPageRoute.php line 95

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\LandingPage\SalesChannel;
  3. use Shopware\Core\Content\Cms\DataResolver\ResolverContext\EntityResolverContext;
  4. use Shopware\Core\Content\Cms\Exception\PageNotFoundException;
  5. use Shopware\Core\Content\Cms\SalesChannel\SalesChannelCmsPageLoaderInterface;
  6. use Shopware\Core\Content\LandingPage\Exception\LandingPageNotFoundException;
  7. use Shopware\Core\Content\LandingPage\LandingPageDefinition;
  8. use Shopware\Core\Content\LandingPage\LandingPageEntity;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  10. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter;
  11. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  12. use Shopware\Core\Framework\Log\Package;
  13. use Shopware\Core\Framework\Plugin\Exception\DecorationPatternException;
  14. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  15. use Shopware\Core\Framework\Routing\Annotation\Since;
  16. use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface;
  17. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. /**
  21.  * @Route(defaults={"_routeScope"={"store-api"}})
  22.  */
  23. #[Package('content')]
  24. class LandingPageRoute extends AbstractLandingPageRoute
  25. {
  26.     /**
  27.      * @var SalesChannelRepositoryInterface
  28.      */
  29.     private $landingPageRepository;
  30.     /**
  31.      * @var SalesChannelCmsPageLoaderInterface
  32.      */
  33.     private $cmsPageLoader;
  34.     /**
  35.      * @var LandingPageDefinition
  36.      */
  37.     private $landingPageDefinition;
  38.     /**
  39.      * @internal
  40.      */
  41.     public function __construct(
  42.         SalesChannelRepositoryInterface $landingPageRepository,
  43.         SalesChannelCmsPageLoaderInterface $cmsPageLoader,
  44.         LandingPageDefinition $landingPageDefinition
  45.     ) {
  46.         $this->landingPageRepository $landingPageRepository;
  47.         $this->cmsPageLoader $cmsPageLoader;
  48.         $this->landingPageDefinition $landingPageDefinition;
  49.     }
  50.     public function getDecorated(): AbstractLandingPageRoute
  51.     {
  52.         throw new DecorationPatternException(self::class);
  53.     }
  54.     /**
  55.      * @Since("6.4.0.0")
  56.      * @Route("/store-api/landing-page/{landingPageId}", name="store-api.landing-page.detail", methods={"POST"})
  57.      */
  58.     public function load(string $landingPageIdRequest $requestSalesChannelContext $context): LandingPageRouteResponse
  59.     {
  60.         $landingPage $this->loadLandingPage($landingPageId$context);
  61.         $pageId $landingPage->getCmsPageId();
  62.         if (!$pageId) {
  63.             return new LandingPageRouteResponse($landingPage);
  64.         }
  65.         $resolverContext = new EntityResolverContext($context$request$this->landingPageDefinition$landingPage);
  66.         $pages $this->cmsPageLoader->load(
  67.             $request,
  68.             $this->createCriteria($pageId$request),
  69.             $context,
  70.             $landingPage->getTranslation('slotConfig'),
  71.             $resolverContext
  72.         );
  73.         if (!$pages->has($pageId)) {
  74.             throw new PageNotFoundException($pageId);
  75.         }
  76.         $landingPage->setCmsPage($pages->get($pageId));
  77.         return new LandingPageRouteResponse($landingPage);
  78.     }
  79.     private function loadLandingPage(string $landingPageIdSalesChannelContext $context): LandingPageEntity
  80.     {
  81.         $criteria = new Criteria([$landingPageId]);
  82.         $criteria->setTitle('landing-page::data');
  83.         $criteria->addFilter(new EqualsFilter('active'true));
  84.         $criteria->addFilter(new EqualsFilter('salesChannels.id'$context->getSalesChannel()->getId()));
  85.         $landingPage $this->landingPageRepository
  86.             ->search($criteria$context)
  87.             ->get($landingPageId);
  88.         if (!$landingPage) {
  89.             throw new LandingPageNotFoundException($landingPageId);
  90.         }
  91.         return $landingPage;
  92.     }
  93.     private function createCriteria(string $pageIdRequest $request): Criteria
  94.     {
  95.         $criteria = new Criteria([$pageId]);
  96.         $criteria->setTitle('landing-page::cms-page');
  97.         $slots $request->get('slots');
  98.         if (\is_string($slots)) {
  99.             $slots explode('|'$slots);
  100.         }
  101.         if (!empty($slots) && \is_array($slots)) {
  102.             $criteria
  103.                 ->getAssociation('sections.blocks')
  104.                 ->addFilter(new EqualsAnyFilter('slots.id'$slots));
  105.         }
  106.         return $criteria;
  107.     }
  108. }