Skip to content

Modify Sitemap Entries

Modify Sitemap Entries

Overview

You might have had a look at our guide about adding custom sitemap entries, for example for a custom entity. However, you might not want to add new URLs, but rather modify already existing ones. This guide covers how to modify existing sitemap URLs (for example product URLs) in a plugin.

Prerequisites

This guide is built upon the Plugin base guide, like most guides.

Knowing service decoration and the sitemap URL provider system from adding custom sitemap entries will be helpful.

Ways to modify sitemap entries

There are two common ways to modify existing sitemap entries.

  1. Decorate a URL provider and adjust the returned UrlResult
  2. Modify the provider query with SitemapQueryEvent (recommended when filtering by entity data)

Decorate a URL provider and adjust the UrlResult

This approach is useful when you only need to adjust sitemap metadata (priority, changefreq, lastmod) or drop entries by identifier.

Start by decorating the corresponding URL provider, for example Shopware\Core\Content\Sitemap\Provider\ProductUrlProvider.

Downside of this approach: You only have sitemap Url structs at this point. If you need to filter by entity fields (for example product name, manufacturer, custom fields), this is usually too late.

Core sitemap providers dispatch SitemapQueryEvent before executing their database query. For products, the event contains the technical name sitemap.query.product.

This is the recommended extension point when you need to:

  • filter entities before URLs are generated
  • add SQL JOINs for entity-based conditions
  • keep your extension more update-compatible than copying provider internals

Important note about getSeoUrls

getSeoUrls is a protected method on AbstractUrlProvider. If you only decorate a provider and forward getUrls() to the inner service, overriding getSeoUrls in your decorator has no effect.

If you really need to change SEO URL lookup internals, you have to implement the provider logic in your own service. This is possible, but less update-compatible because you copy core internals.

Depending on your use case, configuration might already solve your requirement:

  • Remove sitemap entries via shopware.sitemap.excluded_urls
  • product visibility behavior in core via core.sitemap.excludeLinkedProducts
Was this page helpful?
UnsatisfiedSatisfied
Be the first to vote!
0.0 / 5  (0 votes)