0
votes

I'm trying to add a new entity to my email templates so I have: 1) I created a new plugin with my custom entity

        $connection->executeQuery('
            CREATE TABLE IF NOT EXISTS `my_entity` (
              `id` BINARY(16) NOT NULL,
              `message` VARCHAR(255) NOT NULL
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
        ');

2) I have added the first row in this column:

id      | name
bin... | test

3) I edit this record in db: mail_template_type column available_entities {"order":"order","salesChannel":"sales_channel","myEntity":"my_entity"}

And now when I edit the email, twig tells me that there is such a variable to use, but when I use it, there is nothing in it {{ myEntity.name }}

Can I have a clear explanation, how can I do that?

1

1 Answers

0
votes

If you dispatch your own Event to send the mail, you have to implement the getAvailableData function and add your Entity to the Collection

public static function getAvailableData(): EventDataCollection
{
    return (new EventDataCollection())
        ->add('myEntity', new EntityType(MyEntityDefinition::class));
}

Additionally you have to create a getter function to provide the data to the mail template.

public function getMyEntity(): MyEntityEntity
{
    return $this->myEntity;
}

Otherwise if you want to add an entity to an already existing event you can add an association to the entity which is used in the event.