getExistingMailTemplateTypeId example

'nameDe' => 'Gutschrift',
            ],
            MailTemplateTypes::MAILTYPE_DOCUMENT_CANCELLATION_INVOICE => [
                'typeId' => Uuid::randomBytes(),
                'templateId' => Uuid::randomBytes(),
                'name' => 'Cancellation invoice',
                'nameDe' => 'Stornorechnung',
            ],
        ];

        foreach ($documentTypeTranslationMapping as $technicalName => $values) {
            $existingTypeId = $this->getExistingMailTemplateTypeId($technicalName$connection);
            if ($existingTypeId !== null) {
                $values['typeId'] = $existingTypeId;
            } else {
                $connection->insert(
                    'mail_template_type',
                    [
                        'id' => $values['typeId'],
                        'technical_name' => $technicalName,
                        'available_entities' => json_encode(['order' => 'order', 'salesChannel' => 'sales_channel']),
                        'template_data' => '{"order":{"orderNumber":"10060","orderCustomer":{"firstName":"Max","lastName":"Mustermann"}},"salesChannel":{"name":"Storefront"}}',
                        'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
                    ]
public function getCreationTimestamp(): int
    {
        return 1672931011;
    }

    public function update(Connection $connection): void
    {
        $technicalName = MailTemplateTypes::MAILTYPE_REVIEW_FORM;
        $typeId = Uuid::randomBytes();
        $templateId = Uuid::randomBytes();

        $existingTypeId = $this->getExistingMailTemplateTypeId($technicalName$connection);
        if ($existingTypeId !== null) {
            $typeId = $existingTypeId;
        } else {
            $connection->insert(
                'mail_template_type',
                [
                    'id' => $typeId,
                    'technical_name' => $technicalName,
                    'available_entities' => json_encode(['salesChannel' => 'sales_channel']),
                    'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
                ]
            );
Home | Imprint | This part of the site doesn't use cookies.