How do I get the product URL from Shopware 6.
When I 'read' data for a particular product via the product ID, the 'seoURL' field is usually empty. How do I retrieve the correct product URL?
How do I get the product URL from Shopware 6.
When I 'read' data for a particular product via the product ID, the 'seoURL' field is usually empty. How do I retrieve the correct product URL?
Copyright © 2021 Jogjafile Inc.
There are more than one way to do it depending on where you want to do it from, but by using the Database Abstraction Layer (DAL) from PHP, you want to use
getAssociationonseoUrl, and also remember to filter by the language you want.1. First you need to create the context, this is used to fetch the right URL depending on language and sales channel. How exactly to create the context also depends on your specific scenario.
In this example we are altering a HTTP response from a Shopware plugin, so to get the
sales channel idandlanguage id, we can use the request object. E.g:We need these IDs for creating the context itself:
2. For simplicity, this is how to fetch the seo url by
productIdand our created$context:Fyi. It is done in similar ways in the vue.js based administration.
The vue.js based administration
For the administration backend, create the
productRepository:2. Then create a method to fetch a product:
Note: If you want to avoid this huge mess of code to do such a simple thing, sometimes you can "do with" a simple storefront detail-URL, that will be automatically redirected to the actual
seoUrl: