I am trying to lookup the seoUrl of variants displayed on a product detail page – in the configurator.html.twig file. I have the option Id and have tried passing it as productId for the seoUrl function – but it doesn’t return the correct seoUrl.
Searching for a solution, I found this question: Show all variations on the product detail page in Shopware 6 – which also lacks an answer.
But it hinted that you should add the data using a Subscriber – is that really necessary?
2
Answers
Yes, the best solution would be to fetch all variants based on the parentId in a subscriber.
This is necessary because you want to have more data then just the productId. You should also consider this information as necessary:
And optional:
Without the necessary product information the end user will possibly encounter errors when adding a product with a invalid quantity to the cart.
You may decorate the
ProductDetailRoute
, fetch the parent and with its children association and iterate them in the storefront template.Sample output:
Variation on this solution
A little more complex but with a lesser performance impact: