getCmsPage example


        $productId = Uuid::randomHex();
        $request = new Request([][]['productId' => $productId]);
        $salesChannelContext = $this->getSalesChannelContext();
        $reviews = $this->getCmsSlotConfig();

        $productPageLoader = $this->getProductPageLoaderWithProduct($productId$reviews$request$salesChannelContext);

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

        /** @phpstan-ignore-next-line $slot */
        $slot = $page->getCmsPage()->getSections()->first()->getBlocks()->first()->getSlots()->first()->getSlot();

        static::assertEquals($reviewsjson_decode((string) $slot, true, 512, \JSON_THROW_ON_ERROR));
    }

    /** * @param array<string, array<string, array<string, array<string, array<string, string>>>>> $reviews */
    private function getProductPageLoaderWithProduct(string $productId, array $reviews, Request $request, SalesChannelContext $salesChannelContext): ProductPageLoader
    {
        $product = $this->getProductWithReviews($productId$reviews);

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

        $this->hook(new ProductPageLoadedHook($page$context));

        $ratingSuccess = $request->get('success');

        /** * @deprecated tag:v6.6.0 - remove complete if statement, cms page id is always set * * Fallback layout for non-assigned product layout */
        if (!$page->getCmsPage()) {
            Feature::throwException('v6.6.0.0', 'Fallback will be removed because cms page is always set in subscriber.');

            return $this->renderStorefront('@Storefront/storefront/page/product-detail/index.html.twig', ['page' => $page, 'ratingSuccess' => $ratingSuccess]);
        }

        return $this->renderStorefront('@Storefront/storefront/page/content/product-detail.html.twig', ['page' => $page]);
    }

    #[Route(path: '/detail/{productId}/switch', name: 'frontend.detail.switch', defaults: ['XmlHttpRequest' => true, '_httpCache' => true], methods: ['GET'])]     public function switch(string $productId, Request $request, SalesChannelContext $salesChannelContext): JsonResponse
    {
        
$event = new CategoryRouteCacheTagsEvent($navigationId$tags$request$response$context, null);
        $this->dispatcher->dispatch($event);

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

    /** * @return array<string> */
    private function extractProductIds(CategoryRouteResponse $response): array
    {
        $page = $response->getCategory()->getCmsPage();

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

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

        $slots = $page->getElementsOfType('product-slider');
        /** @var CmsSlotEntity $slot */
        foreach ($slots as $slot) {
            
$request = new Request();
        $context = $this->createSalesChannelContextWithNavigation();

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

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

        static::assertInstanceOf(ErrorPage::class$page);
        self::assertPageEvent(ErrorPageLoadedEvent::class$event$context$request$page);
        static::assertSame('404 layout', $page->getCmsPage()->getName());
    }

    protected function getPageLoader()
    {
        return $this->getContainer()->get(ErrorPageLoader::class);
    }

    private function createPage(): string
    {
        $page = [
            'id' => Uuid::randomHex(),
            
'manufacturer' => ['name' => 'test'],
            'cmsPageId' => $cmsPageId,
        ];

        $this->repository->create([$data], Context::createDefaultContext());

        $criteria = new Criteria([$id]);
        $criteria->addAssociation('cmsPage');
        /** @var ProductEntity $product */
        $product = $this->repository->search($criteria, Context::createDefaultContext())->get($id);
        static::assertSame($cmsPageId$product->getCmsPageId());
        $cmsPage = $product->getCmsPage();
        static::assertInstanceOf(CmsPageEntity::class$cmsPage);
        static::assertEquals('product_detail', $cmsPage->getType());
    }

    public function testModifyProductPriceMatrix(): void
    {
        $ruleA = Uuid::randomHex();
        $ruleB = Uuid::randomHex();

        $this->getContainer()->get('rule.repository')->create([
            ['id' => $ruleA, 'name' => 'test', 'priority' => 1],
            [

        $response = $this->request(
            'POST',
            '/checkout/promotion/add',
            $this->tokenize('frontend.checkout.promotion.add', [
                'forwardTo' => 'frontend.home.page',
            ])
        );

        static::assertInstanceOf(StorefrontResponse::class$response);
        static::assertInstanceOf(NavigationPage::class$response->getData()['page']);
        static::assertInstanceOf(CmsPageEntity::class$response->getData()['page']->getCmsPage());
        static::assertSame('Default listing layout', $response->getData()['page']->getCmsPage()->getName());
        static::assertSame(200, $response->getStatusCode());
    }

    public function testForwardFromAddPromotionToApiFails(): void
    {
        $response = $this->request(
            'POST',
            '/checkout/promotion/add',
            $this->tokenize('frontend.checkout.promotion.add', [
                'forwardTo' => 'api.action.user.user-recovery.hash',
            ])
$landingPageLoader->load($request$salesChannelContext);
    }

    public function testItLoads(): void
    {
        $productId = Uuid::randomHex();
        $landingPageId = Uuid::randomHex();
        $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);
    }

    
$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) {
            

    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();
        $metaTitle = $landingPage->getMetaTitle() ?? $landingPage->getName();
        $metaInformation->setMetaTitle($metaTitle ?? '');
        
private readonly EventDispatcherInterface $eventDispatcher
    ) {
    }

    #[Route(path: '/widgets/cms/{id}', name: 'frontend.cms.page', defaults: ['id' => null, 'XmlHttpRequest' => true, '_httpCache' => true], methods: ['GET', 'POST'])]     public function page(?string $id, Request $request, SalesChannelContext $salesChannelContext): Response
    {
        if (!$id) {
            throw RoutingException::missingRequestParameter('id');
        }

        $page = $this->cmsRoute->load($id$request$salesChannelContext)->getCmsPage();

        $this->hook(new CmsPageLoadedHook($page$salesChannelContext));

        $response = $this->renderStorefront('@Storefront/storefront/page/content/detail.html.twig', ['cmsPage' => $page]);
        $response->headers->set('x-robots-tag', 'noindex');

        return $response;
    }

    /** * Navigation id is required to load the slot config for the navigation */
$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([][][
            'landingPageId' => $this->ids->create('landing-page'),
        ]);
$category = $this->cmsPageRoute
            ->load($navigationId$request$context)
            ->getCategory();

        if (!$category->getActive()) {
            throw new CategoryNotFoundException($category->getId());
        }

        $this->loadMetaData($category$page$context->getSalesChannel());
        $page->setNavigationId($category->getId());

        if ($category->getCmsPage()) {
            $page->setCmsPage($category->getCmsPage());
        }

        $this->eventDispatcher->dispatch(
            new NavigationPageLoadedEvent($page$context$request)
        );

        if ($page->getMetaInformation()) {
            $canonical = ($navigationId === $context->getSalesChannel()->getNavigationCategoryId())
                ? $this->seoUrlReplacer->generate('frontend.home.page')
                : $this->seoUrlReplacer->generate('frontend.navigation.page', ['navigationId' => $navigationId]);

            
static::assertEquals($cmsPageId$product->getCmsPageId());
        $request = new Request([][]['productId' => $product->getId()]);

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

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

        static::assertInstanceOf(ProductPage::class$page);
        static::assertInstanceOf(CmsPageEntity::class$page->getCmsPage());
        static::assertEquals($cmsPageId$page->getCmsPage()->getId());

        static::assertSame(StorefrontPageTestConstants::PRODUCT_NAME, $page->getProduct()->getName());
        self::assertPageEvent(ProductPageLoadedEvent::class$event$context$request$page);
    }

    public function testSlotOverwrite(): void
    {
        $context = $this->createSalesChannelContextWithNavigation();
        $cmsPageId = Uuid::randomHex();
        $firstSlotId = Uuid::randomHex();
        


    public function testPageReturn(): void
    {
        $cmsRouteResponse = new CmsRouteResponse(new CmsPageEntity());
        $this->cmsRouteMock->method('load')->willReturn($cmsRouteResponse);

        $ids = new IdsCollection();

        $this->controller->page($ids->get('page')new Request()$this->createMock(SalesChannelContext::class));

        static::assertEquals($cmsRouteResponse->getCmsPage()$this->controller->renderStorefrontParameters['cmsPage']);
    }

    public function testCategoryNoId(): void
    {
        if (Feature::isActive('v6.6.0.0')) {
            $this->expectException(RoutingException::class);
        } else {
            $this->expectException(MissingRequestParameterException::class);
        }
        $this->expectExceptionMessage('Parameter "navigationId" is missing.');

        

        ]);

        $criteria = new Criteria([$childProduct['id']]);
        $criteria->addAssociation('cmsPage');

        $result = $this->repository->search($criteria$context->getContext());

        $childProduct = $result->get($childProduct['id']);
        static::assertInstanceOf(ProductEntity::class$childProduct);
        static::assertEquals($product['id']$childProduct->getParentId());
        static::assertInstanceOf(CmsPageEntity::class$cmsPage = $childProduct->getCmsPage());
        static::assertEquals($expectedCmsPageId$cmsPage->getId());
        static::assertEquals('product_detail', $cmsPage->getType());
    }

    /** * @param array<string, mixed> $config * * @return array<string, mixed> */
    private function createData(array $config = []): array
    {
        
Home | Imprint | This part of the site doesn't use cookies.