HreflangLoaderParameter example

public function addHreflang(StorefrontRenderEvent $event): void
    {
        $request = $event->getRequest();
        $route = $request->attributes->get('_route');

        if ($route === null) {
            return;
        }

        $routeParams = $request->attributes->get('_route_params', []);
        $salesChannelContext = $request->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT);
        $parameter = new HreflangLoaderParameter($route$routeParams$salesChannelContext);
        $event->setParameter('hrefLang', $this->hreflangLoader->load($parameter));
    }

    public function addShopIdParameter(StorefrontRenderEvent $event): void
    {
        if (!$this->activeAppsLoader->getActiveApps()) {
            return;
        }

        try {
            $shopId = $this->shopIdProvider->getShopId();
        }

                'url' => 'https://test.de/en',
                'hreflangUseOnlyLocale' => false,
                'languageId' => $languages->last()->getId(),
                'salesChannelId' => $this->salesChannelContext->getSalesChannel()->getId(),
                'snippetSetId' => $this->getSnippetSetIdForLocale('en-GB'),
                'currencyId' => Defaults::CURRENCY,
            ],
        ]$this->salesChannelContext->getContext());

        $links = $this->hreflangLoader->load(
            new HreflangLoaderParameter('frontend.home.page', []$this->salesChannelContext)
        );

        static::assertInstanceOf(HreflangCollection::class$links);
        static::assertEquals(2, $links->count());
        $foundLinks = 0;

        foreach ($links->getElements() as $element) {
            if ($element->getLocale() === $languages->first()->getLocale()->getCode()) {
                static::assertEquals('https://test.de', $element->getUrl());
                ++$foundLinks;
            }

            
Home | Imprint | This part of the site doesn't use cookies.