patchee500patchee500 MemberComments: 11 Received thanks: 6 Member since: February 9

Or rather how is multilang supposed to work when qerying data from the Admin API in general?

This is my specific usecase:

Suppose I'm only using a single Storefront with multiple languages. 

I'd like to select certain products that have some text in a specific language (in my case) in a translatable custom field. So far what I have achieved is getting the products when the entry in the (default?) English language matches:

http://localhost:8000/api/v1/search/product
{
    "filter": [
        { 
            "type": "equals", 
            "field": "customFields.my_custom_field", 
            "value":  "some_key_in_a_specific_language"
        }    
    ]
}

As mentioned, this returns matching producs that have "some_key_in_a_specific_language" in the english translation of that custom field.
Now, how can I perform the same request querying another language? I struggle to find any documentation on switching the context used when querying the Admin API.

Furthermore, how can I retrieve translations of products or other data in general through the API?

Writing translatable data seems to be no problem as different translations can be supplied within the payload used to create the product as described here: 
https://docs.shopware.com/en/shopware-platform-dev-en/internals/core/data-abstraction-layer/translation-handling?category=shopware-platform-dev-en/internals/core/data-abstraction-layer

Answers

  • patchee500patchee500 MemberComments: 11 Received thanks: 6 Member since: February 9

    Figured it out.

    It's possible to pass the 'sw-language-id' Header with a specified language id.

    Magic happens in \Shopware\Core\Framework\Routing\ApiRequestContextResolver::getRuntimeParameters

    Some documentation would have been nice here.

    Note that specified unique id of the langauge must follow the Regex in \Shopware\Core\Framework\Uuid\Uuid::VALID_PATTERN, otherwise some validation check fails.

Sign In or Register to comment.