getSeoUrls example

static::assertEquals(SeoUrlRouteNotFoundException::ERROR_CODE, $result['errors'][0]['code']);
    }

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

        $id = $this->createTestProduct($salesChannelId);

        $seoUrls = $this->getSeoUrls($id, true, $salesChannelId);
        static::assertCount(1, $seoUrls);

        $seoUrl = $seoUrls[0]['attributes'];
        static::assertFalse($seoUrl['isModified']);

        $newSeoPathInfo = 'my-awesome-seo-path';
        $seoUrl['seoPathInfo'] = $newSeoPathInfo;
        $seoUrl['isModified'] = true;

        // modify canonical         $this->getBrowser()->request('PATCH', '/api/_action/seo-url/canonical', $seoUrl);
        

    public function getUrls(SalesChannelContext $context, int $limit, ?int $offset = null): UrlResult
    {
        $categories = $this->getCategories($context$limit$offset);

        if (empty($categories)) {
            return new UrlResult([], null);
        }
        $keys = FetchModeHelper::keyPair($categories);

        $seoUrls = $this->getSeoUrls(array_values($keys), 'frontend.navigation.page', $context$this->connection);

        $seoUrls = FetchModeHelper::groupUnique($seoUrls);

        $urls = [];
        $url = new Url();

        foreach ($categories as $category) {
            if (!isset($seoUrls[$category['id']])) {
                continue;
            }

            
public function testDefaultNew(): void
    {
        $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);
        

                'id' => $salesChannelContext->getSalesChannelId(),
            ],
        ]]);

        $criteria = new Criteria([$id]);
        $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();
        
$criteria->addFilter(new EqualsFilter('isCanonical', true));
            $criteria->addFilter(new EqualsAnyFilter('routeName', $routes));
            $criteria->addFilter(new EqualsAnyFilter('foreignKey', $ids));
            $criteria->addFilter(new EqualsFilter('languageId', $context->getContext()->getLanguageId()));
            $criteria->addSorting(new FieldSorting('salesChannelId'));

            /** @var SeoUrlEntity $url */
            foreach ($this->salesChannelRepository->search($criteria$context) as $url) {
                /** @var SalesChannelProductEntity|CategoryEntity $entity */
                $entity = $data->get($definition$url->getForeignKey());

                if ($entity->getSeoUrls() === null) {
                    $entity->setSeoUrls(new SeoUrlCollection());
                }

                /** @phpstan-ignore-next-line - will complain that 'getSeoUrls' might be null, but we will set it if it is null */
                $entity->getSeoUrls()->add($url);
            }
        }
    }
}
'name' => 'test',
                'seoUrls' => $data,
            ],
        ], 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);

        

    public function getUrls(SalesChannelContext $context, int $limit, ?int $offset = null): UrlResult
    {
        $products = $this->getProducts($context$limit$offset);

        if (empty($products)) {
            return new UrlResult([], null);
        }

        $keys = FetchModeHelper::keyPair($products);

        $seoUrls = $this->getSeoUrls(array_values($keys), 'frontend.detail.page', $context$this->connection);

        $seoUrls = FetchModeHelper::groupUnique($seoUrls);

        $urls = [];
        $url = new Url();

        foreach ($products as $product) {
            $lastMod = $product['updated_at'] ?: $product['created_at'];

            $lastMod = (new \DateTime($lastMod))->format(Defaults::STORAGE_DATE_TIME_FORMAT);

            
public function testGenerateForNewCategories(): void
    {
        $ids = new TestDataCollection();

        $categories = [
            ['id' => $ids->create('root'), 'name' => 'root'],
        ];

        $this->categoryRepository->create($categories, Context::createDefaultContext());

        $urls = $this->getSeoUrls($ids->getList(['root']), null);
        static::assertEmpty($urls);

        $this->createSalesChannel($ids->create('sales-channel')$ids->get('root'));

        $categories = [
            ['id' => $ids->create('a'), 'name' => 'a', 'parentId' => $ids->get('root')],
            ['id' => $ids->create('b'), 'name' => 'b', 'parentId' => $ids->get('a')],
        ];

        $this->categoryRepository->create($categories, Context::createDefaultContext());

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