getLandingPage example

/** * @param int $emotionId * * @throws Exception * @throws Enlight_Controller_Exception * * @return LandingPageViewStruct */
    public function load($emotionId, ShopContextInterface $context)
    {
        $landingPage = $this->deviceConfiguration->getLandingPage($emotionId);
        $landingPageShops = $this->deviceConfiguration->getLandingPageShops($emotionId);

        $shopId = $context->getShop()->getId();
        $fallbackId = $context->getShop()->getFallbackId();

        if (!$landingPage || !\in_array($shopId$landingPageShops)) {
            throw new Enlight_Controller_Exception('Landing page missing, non-existent or invalid for the current shop', 404);
        }

        $translation = $this->translationComponent->readWithFallback($shopId$fallbackId, 'emotion', $emotionId);

        
$request = new Request([][]['landingPageId' => $landingPageId]);
        $salesChannelContext = $this->getSalesChannelContext();

        $product = $this->getProduct($productId);
        $cmsPage = $this->getCmsPage($product);

        $landingPageLoader = $this->getLandingPageLoaderWithProduct($landingPageId$cmsPage$request$salesChannelContext);

        $page = $landingPageLoader->load($request$salesChannelContext);

        /** @phpstan-ignore-next-line */
        $cmsPageLoaded = $page->getLandingPage()->getCmsPage();

        static::assertEquals($cmsPage$cmsPageLoaded);
    }

    private function getLandingPageLoaderWithProduct(string $landingPageId, CmsPageEntity $cmsPage, Request $request, SalesChannelContext $salesChannelContext): LandingPageLoader
    {
        $landingPage = new LandingPageEntity();
        $landingPage->setId($landingPageId);
        $landingPage->setCmsPage($cmsPage);

        $landingPageRouteMock = $this->createMock(LandingPageRoute::class);
        
$event = new LandingPageRouteCacheTagsEvent($landingPageId$tags$request$response$context, null);
        $this->dispatcher->dispatch($event);

        return array_unique(array_filter($event->getTags()));
    }

    /** * @return array<string> */
    private function extractIds(LandingPageRouteResponse $response): array
    {
        $page = $response->getLandingPage()->getCmsPage();

        if ($page === null) {
            return [];
        }

        $ids = [];
        $streamIds = [];

        $slots = $page->getElementsOfType('product-slider');
        /** @var CmsSlotEntity $slot */
        foreach ($slots as $slot) {
            
$this->ids->set('sales-channel', $context->getSalesChannelId());
        $this->createData();

        /** @var LandingPageLoadedEvent $event */
        $event = null;
        $this->catchEvent(LandingPageLoadedEvent::class$event);

        $page = $this->getPageLoader()->load($request$context);

        static::assertInstanceOf(LandingPage::class$page);

        static::assertInstanceOf(LandingPageEntity::class$page->getLandingPage());
        static::assertInstanceOf(CmsPageEntity::class$page->getLandingPage()->getCmsPage());
        static::assertSame($this->ids->get('cms-page')$page->getLandingPage()->getCmsPage()->getId());

        self::assertPageEvent(LandingPageLoadedEvent::class$event$context$request$page);
    }

    public function testLoadWithInactiveLandingPage(): void
    {
        $this->ids = new TestDataCollection();

        $request = new Request([][][
            
/** * @throws PageNotFoundException */
    public function load(Request $request, SalesChannelContext $context): LandingPage
    {
        $landingPageId = $request->attributes->get('landingPageId');
        if (!$landingPageId) {
            throw RoutingException::missingRequestParameter('landingPageId', '/landingPageId');
        }

        $landingPage = $this->landingPageRoute->load($landingPageId$request$context)->getLandingPage();

        if ($landingPage->getCmsPage() === null) {
            throw new PageNotFoundException($landingPageId);
        }

        $page = $this->genericPageLoader->load($request$context);
        $page = LandingPage::createFrom($page);

        $page->setLandingPage($landingPage);

        $metaInformation = new MetaInformation();
        
Home | Imprint | This part of the site doesn't use cookies.