在Shopware 6.5中导入导出配置文件 – 如何使用ImportExportBeforeImportRecordEvent

huangapple go评论53阅读模式
英文:

Import Export Profil in Shopware 6.5 - how to use ImportExportBeforeImportRecordEvent

问题

在 Shopware 6.4 中,我们为我们的插件创建了一个单独的导入/导出配置文件,并使用了EntityRepositoryDecorator。在 Shopware 6.5 中,不再存在EntityRepositoryDecorator。目标是在导入数据写入数据库之前更改实体的数据。为此,我们可以使用事件ImportExportBeforeImportRecordEvent,不幸的是,我们没有关于正在导入哪个实体的信息,也无法检查。我们无法为每个单独的实体执行更改数据的代码。

英文:

In Shopware 6.4 we created a separate import / export profile for our plugin and used EntityRepositoryDecorator.
With Shopware 6.5 there is no longer an EntityRepositoryDecorator.
The goal is to change the data of the entity during import before it is written to the database. For this we could use the event ImportExportBeforeImportRecordEvent, unfortunately we have no information about which entity is being imported and cannot check this. We cannot execute the code to change the data for each individual entity.

答案1

得分: 1

你可以从事件提供的配置中获取实体名称。

public function callbackMethodName($event): void
{
    $entityName = $event->getConfig()->get('sourceEntity');
    // ...
}

参见ProductCategoryPathsSubscriber以获取示例。

英文:

You can get the entity name from the config provided by the event.

public function callbackMethodName $event): void
{
    $entityName = $event->getConfig()->get('sourceEntity');
    // ...
}

See ProductCategoryPathsSubscriber for an example.

huangapple
  • 本文由 发表于 2023年6月15日 03:21:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76476914.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定