getSeoPathInfo example


        ], Context::createDefaultContext());

        $criteria = new Criteria([$id]);
        $modifier($criteria);

        /** @var CategoryEntity $result */
        $result = $this->categoryRepository->search($criteria, Context::createDefaultContext())->first();

        $seoUrlCollection = $result->getSeoUrls();
        static::assertNotNull($seoUrlCollection);
        $urls = $seoUrlCollection->map(fn (SeoUrlEntity $e) => $e->getSeoPathInfo());

        static::assertSame($expectedarray_values($urls));
    }

    public function testLoadOneToManyPaginatedWithNoParent(): void
    {
        $context = Context::createDefaultContext();
        $context->setConsiderInheritance(true);

        $this->productRepository->create([
            [
                

        $salesChannelId = Uuid::randomHex();
        $salesChannelContext = $this->createStorefrontSalesChannelContext($salesChannelId, 'test');

        $id = Uuid::randomHex();
        $this->upsertProduct(['id' => $id, 'name' => 'awesome product', 'productNumber' => 'P1']$salesChannelId);

        $product = $this->productRepository->search($this->getCriteria($id$salesChannelId)$salesChannelContext->getContext())->first();

        static::assertNotNull($product->getSeoUrls());
        $canonicalUrl = $product->getSeoUrls()->first();
        static::assertSame('awesome-product/P1', $canonicalUrl->getSeoPathInfo());

        $seoUrls = $this->getSeoUrls($salesChannelId$id);
        $canonicalUrls = $seoUrls->filterByProperty('isCanonical', true);
        $nonCanonicals = $seoUrls->filterByProperty('isCanonical', false);

        static::assertSame($canonicalUrl->getId()$canonicalUrls->first()->getId());

        static::assertCount(1, $canonicalUrls);
        static::assertCount(0, $nonCanonicals);
        static::assertCount(1, $seoUrls);
    }

    
$urls = $this->getSeoUrlsById($id);

        static::assertCount(1, $urls);

        $url = $urls->first();

        static::assertNotNull($url);
        static::assertSame($s1$url->getSalesChannelId());
        static::assertSame($id$url->getForeignKey());
        static::assertSame('frontend.account.customer-group-registration.page', $url->getRouteName());
        static::assertSame('test', $url->getSeoPathInfo());
    }

    public function testUrlsAreForHeadlessSalesChannelAreHanldedCorrectly(): void
    {
        $s1 = $this->createSalesChannel(['typeId' => Defaults::SALES_CHANNEL_TYPE_API])['id'];

        $id = Uuid::randomHex();

        $this->customerGroupRepository->create([
            [
                'id' => $id,
                
$copy = clone $seoUrl;

            $mapping = $seoUrlRoute->getMapping($entity$salesChannel);

            $copy->setError($mapping->getError());
            $pathInfo = $this->router->generate($config->getRouteName()$mapping->getInfoPathContext());
            $pathInfo = $this->removePrefix($pathInfo$basePath);

            $copy->setPathInfo($pathInfo);

            $seoPathInfo = $this->getSeoPathInfo($mapping$config);

            if ($seoPathInfo === null || $seoPathInfo === '') {
                continue;
            }

            $copy->setSeoPathInfo($seoPathInfo);
            $copy->setSalesChannelId($salesChannel->getId());

            yield $copy;
        }
    }

    
'id' => $id,
            'seoPathInfo' => '/even/prettier/path',
        ];
        $events = $repo->update([$update]$context);
        $event = $events->getEventByEntityName(SeoUrlDefinition::ENTITY_NAME);
        static::assertNotNull($event);
        static::assertCount(1, $event->getPayloads());

        /** @var SeoUrlEntity $first */
        $first = $repo->search(new Criteria([$id])$context)->first();
        static::assertEquals($update['id']$first->getId());
        static::assertEquals($update['seoPathInfo']$first->getSeoPathInfo());
    }

    public function testDelete(): void
    {
        $id = Uuid::randomHex();
        $fk = Uuid::randomHex();
        $url = [
            'id' => $id,
            'salesChannelId' => TestDefaults::SALES_CHANNEL,
            'foreignKey' => $fk,

            
$criteria->addAssociation('seoUrls');

        /** @var LandingPageEntity $landingPage */
        $landingPage = $this->landingPageRepository->search($criteria$salesChannelContext->getContext())->first();

        static::assertInstanceOf(SeoUrlCollection::class$landingPage->getSeoUrls());

        /** @var SeoUrlCollection $seoUrls */
        $seoUrls = $landingPage->getSeoUrls();
        $seoUrl = $seoUrls->first();
        static::assertInstanceOf(SeoUrlEntity::class$seoUrl);
        static::assertEquals('coolUrl', $seoUrl->getSeoPathInfo());
    }

    public function testLandingPageUpdate(): void
    {
        $salesChannelId = Uuid::randomHex();
        $salesChannelContext = $this->createStorefrontSalesChannelContext($salesChannelId, 'test');

        $id = $this->createTestLandingPage(['salesChannels' => [
            [
                'id' => $salesChannelContext->getSalesChannelId(),
            ],
        ]]);
$urls = $this->seoUrlGenerator->generate(
            [$id],
            $template,
            $route,
            $this->salesChannelContext->getContext(),
            $this->salesChannelContext->getSalesChannel()
        );

        static::assertIsIterable($urls);

        foreach ($urls as $url) {
            static::assertStringEndsWith($pathInfo$url->getSeoPathInfo());
        }
    }

    /** * @return list<array{template: string, count: int, pathInfo: string}> */
    public static function templateDataProvider(): array
    {
        $connection = KernelLifecycleManager::getConnection();

        $categoryId = Uuid::fromBytesToHex((string) $connection->fetchOne('SELECT id FROM category'));

        
$criteria->addFilter(new EqualsFilter('routeName', TestProductSeoUrlRoute::ROUTE_NAME));
        $criteria->addFilter(new EqualsFilter('salesChannelId', $this->storefrontSalesChannel['id']));
        $seoUrl = $this->getContainer()->get('seo_url.repository')->search(
            $criteria,
            Context::createDefaultContext()
        )->first();

        // Check if seo url was created         static::assertNotNull($seoUrl);

        // Check if seo path matches the expected path         static::assertStringStartsWith($pathInfo$seoUrl->getSeoPathInfo());

        // Verify URL of headless sales channel.         $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('routeName', TestProductSeoUrlRoute::ROUTE_NAME));
        $criteria->addFilter(new EqualsFilter('salesChannelId', $this->headlessSalesChannel['id']));
        $seoUrl = $this->getContainer()->get('seo_url.repository')->search(
            $criteria,
            Context::createDefaultContext()
        )->first();

        if (Feature::isActive('v6.6.0.0')) {
            

        ];
        $this->seoUrlPersister->updateSeoUrls($context, 'foo.route', array_column($seoUrlUpdates, 'foreignKey')$seoUrlUpdates$this->salesChannel);
        $seoUrls = $this->seoUrlRepository->search(new Criteria(), Context::createDefaultContext())->getEntities();

        static::assertCount(2, $seoUrls);

        $canonicalUrls = $seoUrls->filterByProperty('isCanonical', true);
        static::assertCount(1, $canonicalUrls);
        /** @var SeoUrlEntity $first */
        $first = $canonicalUrls->first();
        static::assertSame('fancy-path-2', $first->getSeoPathInfo());

        $obsoletedSeoUrls = $seoUrls->filterByProperty('isCanonical', null);

        static::assertCount(1, $obsoletedSeoUrls);
        /** @var SeoUrlEntity $first */
        $first = $obsoletedSeoUrls->first();
        static::assertSame('fancy-path', $first->getSeoPathInfo());
    }

    public function testDuplicatesSameSalesChannel(): void
    {
        
Home | Imprint | This part of the site doesn't use cookies.