Skip to content

Commit

Permalink
NEXT-37588 - Exclude folder categories from sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
lacknere authored and LarsKemper committed Aug 8, 2024
1 parent d5e6c4f commit 6c1b530
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Exclude folder categories from sitemap
issue: NEXT-00000
author: Elias Lackner
author_email: [email protected]
author_github: @lacknere
---
# Core
* Changed `CategoryUrlProvider::getCategories` to exclude categories of type `folder`.
2 changes: 2 additions & 0 deletions src/Core/Content/Sitemap/Provider/CategoryUrlProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ private function getCategories(SalesChannelContext $context, int $limit, ?int $o
$query->andWhere('`category`.version_id = :versionId');
$query->andWhere('`category`.active = 1');
$query->andWhere('`category`.type != :linkType');
$query->andWhere('`category`.type != :folderType');

$excludedCategoryIds = $this->getExcludedCategoryIds($context);
if (!empty($excludedCategoryIds)) {
Expand All @@ -138,6 +139,7 @@ private function getCategories(SalesChannelContext $context, int $limit, ?int $o

$query->setParameter('versionId', Uuid::fromHexToBytes(Defaults::LIVE_VERSION));
$query->setParameter('linkType', CategoryDefinition::TYPE_LINK);
$query->setParameter('folderType', CategoryDefinition::TYPE_FOLDER);

/** @var list<array{id: string, created_at: string, updated_at: string}> $result */
$result = $query->executeQuery()->fetchAllAssociative();
Expand Down
17 changes: 15 additions & 2 deletions src/Core/Content/Test/Sitemap/Provider/CategoryUrlProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,16 @@ public function testReturnedOffsetIsValid(): void
static::assertNull($urlResult->getNextOffset());
}

public function testExcludeCategoryLink(): void
public function testExcludeCategoryLinkAndFolder(): void
{
$urlResult = $this->getCategoryUrlProvider()->getUrls($this->salesChannelContext, 10);
static::assertCount(4, $urlResult->getUrls());
$ids = array_map(fn ($url) => $url->getIdentifier(), $urlResult->getUrls());

// link
static::assertNotContains('0191233394c57345a56e1b4df4db81c3', $ids);

// folder
static::assertNotContains('0191233394c57345a56e1b4df521dca6', $ids);
}

private function getCategoryUrlProvider(): CategoryUrlProvider
Expand Down Expand Up @@ -142,10 +148,17 @@ private function createCategoryTree(string $rootId): void
'active' => true,
],
[
'id' => '0191233394c57345a56e1b4df4db81c3',
'name' => 'Sub 5',
'active' => true,
'type' => CategoryDefinition::TYPE_LINK,
],
[
'id' => '0191233394c57345a56e1b4df521dca6',
'name' => 'Sub 6',
'active' => true,
'type' => CategoryDefinition::TYPE_FOLDER,
],
],
],
], Context::createDefaultContext());
Expand Down

0 comments on commit 6c1b530

Please sign in to comment.