getUrls example

$domain = new SalesChannelDomainEntity();
        $domain->setId(Uuid::randomHex());
        $domain->setUrl('https://test-sitemap.de/en');
        $domain->setHreflangUseOnlyLocale(false);
        $domain->setLanguageId($languages->last()->getId());

        $this->salesChannelContext->getSalesChannel()->getDomains()->add($domain);

        $homeUrlProvider = new HomeUrlProvider();

        static::assertCount(1, $homeUrlProvider->getUrls($this->salesChannelContext, 100)->getUrls());
    }

    public function testGetHomeUrlWithSalesChannelIsExistingOneDomain(): void
    {
        $criteria = new Criteria();
        $criteria->addAssociation('locale');
        $languages = $this->getContainer()->get('language.repository')->search($criteria$this->salesChannelContext->getContext())->getEntities();

        $languageId = $this->salesChannelContext->getLanguageId();
        $language = $languages->get($languageId);

        

    public function getUrls(array $parameters, ShopContextInterface $contextService)
    {
        $shop = $contextService->getShop();
        $cacheKey = md5(json_encode($parameters) . ($shop->getParentId() ?: $shop->getId()));

        if ($urls = $this->cache->load($cacheKey)) {
            return $urls;
        }

        $urls = $this->hrefLangService->getUrls($parameters$contextService);

        $this->cache->save($urls$cacheKey[CacheManager::ITEM_TAG_CONFIG], 86400);

        return $urls;
    }
}
$shop,
                $this->container->get(Shopware_Components_Config::class)
            );

            // Gathering URLs             $urls = [];
            $totalResultCount = 0;
            $offset = 0;
            foreach ($options as $resource => $active) {
                if ($active) {
                    $provider = $urlProviderFactory->getProvider($resource);
                    $urls = array_merge($urls$provider->getUrls($context));
                    $totalResultCount += $provider->getCount($context);
                }
            }

            // Progressbar             $progressBar = $io->createProgressBar($totalResultCount);
            $io->writeln(sprintf("\nShop '%s' (ID: %s)", $shop->getName()$shop->getId()));
            $progressBar->setBarWidth(100);
            $progressBar->setFormat('very_verbose');
            $progressBar->start();

            
if (!$request->getParam('error_handler') && $this->get(Shopware_Components_Config::class)->get('hrefLangEnabled')) {
            $context = $this->get(ContextServiceInterface::class)->getShopContext();

            $params = $request->getParams();
            $sCategoryContent = $view->getAssign('sCategoryContent');

            if ($sCategoryContent && $request->getControllerName() === 'listing' && isset($sCategoryContent['canonicalParams']) && \is_array($sCategoryContent['canonicalParams'])) {
                $params = $sCategoryContent['canonicalParams'];
            }

            $view->assign('sHrefLinks', $this->get('shopware_storefront.cached_href_lang_service')->getUrls($params$context));
        }

        $view->assign('SeoDescriptionMaxLength', (int) $this->get(Shopware_Components_Config::class)->get('metaDescriptionLength'));
    }

    /** * Remove html-comments / whitespaces * * @return mixed|string */
    public function onFilterRender(Enlight_Event_EventArgs $args)
    {


        $context = Context::createFromShop($shopModelShopware()->Config());

        $limit = (int) $this->Request()->get('limit');
        $offset = (int) $this->Request()->get('offset');
        $concurrentRequests = (int) $this->Request()->getParam('concurrent', 1);

        $resource = $this->Request()->get('resource');
        $provider = $urlProviderFactory->getProvider($resource);

        $urls = $provider->getUrls($context$limit$offset);

        $view = $this->View();

        $this->get('events')->addListener('Shopware_Components_CacheWarmer_ErrorOccured', function D) use ($view) {
            $view->assign('requestFailed', true);
        });

        $cacheWarmer->warmUpUrls($urls$context$concurrentRequests);

        $this->View()->assign([
            'success' => true,
            
public function generate(Shop $shop)
    {
        if (!$this->sitemapLock->doLock($shop$this->shopwareConfig->get('sitemapRefreshTime'))) {
            throw new AlreadyLockedException(sprintf('Cannot acquire lock for shop %d', $shop->getId()));
        }

        $routerContext = Context::createFromShop($shop$this->shopwareConfig);
        $shopContext = $this->contextService->createShopContext($shop->getId()$shop->getCurrency()->getId()$shop->getCustomerGroup()->getKey());

        foreach ($this->urlProvider as $urlProvider) {
            $urlProvider->reset();
            while ($urls = $urlProvider->getUrls($routerContext$shopContext)) {
                $urls = $this->urlFilter->filter($urls(int) $shop->getId());

                if (!$urls) {
                    continue;
                }

                $this->sitemapWriter->writeFile($shop$urls);
            }
        }

        $this->sitemapWriter->closeFiles();

        

    public function getAllHosts(): array
    {
        $hosts = $this->allowedHosts ? $this->allowedHosts->getHosts() : [];

        $urls = [];
        if ($this->setup) {
            $urls[] = $this->setup->getRegistrationUrl();
        }

        if ($this->webhooks) {
            $urls = \array_merge($urls$this->webhooks->getUrls());
        }

        if ($this->admin) {
            $urls = \array_merge($urls$this->admin->getUrls());
        }

        if ($this->payments) {
            $urls = \array_merge($urls$this->payments->getUrls());
        }

        if ($this->tax) {
            
/** * @return array<string, mixed> */
    private function getDetail(string $name): array
    {
        $typeObj = $this->typeProvider->getType($name);

        $type = json_decode(json_encode($typeObj, JSON_THROW_ON_ERROR), true);
        $type['id'] = $type['internalName'];
        $type['controllerName'] = $typeObj->getControllerName();
        $type['urls'] = $this->getUrls($typeObj);

        return $type;
    }

    /** * @param array<string, mixed> $data */
    private function convertExtJsToStruct(array $data): Type
    {
        unset($data['id']$data['source']$data['urls']$data['controllerName']);

        
public function testGetUrlsReturnsNoUrls(): void
    {
        $configHandlerStub = $this->createMock(ConfigHandler::class);
        $configHandlerStub->method('get')
            ->with(ConfigHandler::CUSTOM_URLS_KEY)
            ->willReturn([]);

        $customUrlProvider = $this->getCustomUrlProvider($configHandlerStub);

        $salesChannelContext = $this->createMock(SalesChannelContext::class);

        static::assertSame([]$customUrlProvider->getUrls($salesChannelContext, 100)->getUrls());
    }

    public function testGetUrlsReturnsAllUrlsForSalesChannel(): void
    {
        $salesChannelContext = $this->createMock(SalesChannelContext::class);

        $configHandlerStub = $this->createMock(ConfigHandler::class);
        $configHandlerStub->method('get')
            ->with(ConfigHandler::CUSTOM_URLS_KEY)
            ->willReturn([
                [
                    

    public function generate(SalesChannelContext $context, bool $force = false, ?string $lastProvider = null, ?int $offset = null): SitemapGenerationResult
    {
        $this->lock($context$force);

        try {
            $this->initSitemapHandles($context);

            foreach ($this->urlProvider as $urlProvider) {
                do {
                    $result = $urlProvider->getUrls($context$this->batchSize, $offset);

                    $this->processSiteMapHandles($result);

                    $needRun = $result->getNextOffset() !== null;
                    $offset = $result->getNextOffset();
                } while ($needRun);
            }

            $this->finishSitemapHandles();
        } finally {
            $this->unlock($context);
        }
$this->productRepository = $this->getContainer()->get('product.repository');
        $this->seoUrlPlaceholderHandler = $this->getContainer()->get(SeoUrlPlaceholderHandlerInterface::class);
        $this->systemConfigService = $this->getContainer()->get(SystemConfigService::class);

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

    public function testProductUrlObjectContainsValidContent(): void
    {
        $products = $this->createProducts();

        $urlResult = $this->getProductUrlProvider()->getUrls($this->salesChannelContext, 5);

        $urls = $urlResult->getUrls();

        $firstUrl = $urls[0];

        static::assertSame('hourly', $firstUrl->getChangefreq());
        static::assertSame(0.5, $firstUrl->getPriority());
        static::assertSame(ProductEntity::class$firstUrl->getResource());
        static::assertTrue(Uuid::isValid($firstUrl->getIdentifier()));

        $host = $this->getHost($this->salesChannelContext);

        
'test-category-sitemap',
            Defaults::LANGUAGE_SYSTEM,
            [],
            $navigationCategoryId
        );

        $this->createCategoryTree($navigationCategoryId);
    }

    public function testCategoryUrlObjectContainsValidContent(): void
    {
        $urlResult = $this->getCategoryUrlProvider()->getUrls($this->salesChannelContext, 5);
        [$firstUrl] = $urlResult->getUrls();

        static::assertSame('daily', $firstUrl->getChangefreq());
        static::assertSame(0.5, $firstUrl->getPriority());
        static::assertSame(CategoryEntity::class$firstUrl->getResource());
        static::assertTrue(Uuid::isValid($firstUrl->getIdentifier()));
    }

    public function testReturnedOffsetIsValid(): void
    {
        $categoryUrlProvider = $this->getCategoryUrlProvider();

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