Update customField in all languages simultaneously

Viewed 66

Is there a way to simultaneously update a customField and all of its translations?
Right now the code looks like this (from a cli command)

$context = Context::createDefaultContext();
$data = [[
    'id' => $productId,
    'customFields' => [
        'product_is_new' => true
    ]
]];
$this->productRepository->update($data, $context);

This only updates the custom field in the main language, I suppose this is because of the default context. What is the way to go to update the customField and all of its translations?

1 Answers

You need to provide CustomFields for each language. E.G.

$data = [
        'id' => $productId,
        'translations' => [
            'languageId1' => [
                'customFields' => [
                    'product_is_new' => true
                ]
            ],
            'languageId2' => [
                'customFields' => [
                    'product_is_new' => true
                ]
            ],
        ]
];
$this->productRepository->update($data, $context);
Related