A colleague wrote a plugin and the customer said, the translation doesn’t work. Our plugin loads more data via a form and AJAX.
The problem: Always queries base url
The problem is, that our JS plugin always queries the base url https://example.com
instead of https://example.com/en
so Shopware didn’t had any chance to find the correct sales channel.
I replaced the hardcoded urls with JS configuration as documented. The next step was to add the dynamic url. I tried it with {{ url() }}
and with {{ path() }}
, but it didn’t work. Symfony or shopware didn’t add the /en
.
The solution: seoUrl
It took a while of fiddling, but after the penny dropped, I looked up how product urls are generated:
{{ seoUrl('my.api.url') }}
Update (23.01.24):
seoUrl
only returns a path, not a complete url, so in case, that your language urls are subdomains, you might want to use rawUrl
instead.
3 thoughts on “Shopware 6: How to URL”