php - 在 Shopware 6 中将自定义实体添加到电子邮件模板
问题描述
我正在尝试向我的电子邮件模板添加一个新实体,所以我有:1)我用我的自定义实体创建了一个新插件
$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)我在此列中添加了第一行:
id | name
bin... | test
3) 我在 db: mail_template_type
column中编辑这条记录available_entities
{"order":"order","salesChannel":"sales_channel","myEntity":"my_entity"}
现在当我编辑邮件时,twig 告诉我有这样一个变量可以使用,但是当我使用它时,里面什么都没有{{ myEntity.name }}
我可以有一个明确的解释,我该怎么做?
解决方案
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.
推荐阅读
- angular - 通过指令禁用表单组
- javascript - 将类/文本添加到 jQuery 元素
- google-cloud-platform - 我们可以为 GCS 存储桶中的特定文件夹/对象设置保留策略吗?
- c++ - 带有结构的生成器模式
- javascript - 使用 DOM 和 ejs 从表中选择随机行
- sql - 我想要三个表的左外连接
- python - 时间序列预测的自相关图python解释?
- python - 如何使用滚动在python中加载弹性数据?
- windows - 搜索 word 文档 (.rtf) 并更改图像分辨率的脚本
- python - 如何将变量导入到我在 python 中保存函数的文件?