Search code examples
shopwareshopware6

How to add category-slugs to a product URL in Shopware 6?


By default, the Shopware 6 URLs for products are set like this:

{{ product.translated.name }}/{{ product.productNumber}}
=> /Product-Name/Number123

Category URLs look like this:

{% for part in category.seoBreadcrumb%}{{ part|lower }}/{% endfor %}
=> /parent-category/child-category

I would like to add the product's main category's path to the product URL like it was possible in SW5 with {sCategoryPath articleID=$sArticle.id}/{$sArticle.name}
=> /parent-category/child-category/product-name

Is there a way to achieve this in SW6?


Solution

  • You can do this out-of-the-box. Tested in Shopware 6.4.15.0:

    {% for part in product.mainCategory.breadcrumb|slice(1)%}{{ part }}/{% endfor %}{{ product.translated.name }}/{{ product.productNumber }}
    

    Will result in:

    enter image description here

    Category structure:

    enter image description here