Search code examples
shopwareshopware6

Updating a mail template type causes the creation of its translation


I encountered an issue while using a language shop that was added afterward and is not EN or DE. I have a function that simply updates the template data of my mail template type.

$this->mailTemplateTypeRepository->update([[
    'id' => $mailTemplateType->getId(),
    'templateData' => $data
]], $context->getContext());

But for whatever reason, it tries to create a new mail_template_type_translation and that causes an exception:

An exception occurred while executing 'INSERT INTO `mail_template_type_translation` (`mail_template_type_id`, `language_id`, `name`, `created_at`) VALUES ('�>yd�Kͤh�Qu��H','�x\r^z�C��p�p;U',NULL,'2022-10-06 11:36:48.844');'
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null

The translations for the language shop don't exist for the mail template type and I don't want to add them, it should just use the fallback language for such translations. And simply adding a none translated field seems to cause the creation of its translations in a particular language.


Solution

  • You could change the languageIdChain property of the Context to include only the default language for translations.

    $clonedContext = clone $context->getContext();
    $clonedContext->assign(['languageIdChain' => [Defaults::LANGUAGE_SYSTEM]]);
    
    $this->mailTemplateTypeRepository->update([[
        'id' => $mailTemplateType->getId(),
        'templateData' => $data
    ]], $clonedContext);