从为 Shopware 5.2 编写的插件访问旧版 Shopware 插件

Accessing a legacy Shopware plugin from one written for Shopware 5.2

我正在为 Shopware 5.2 开发一个插件。 但是,在我的应用程序中,还有升级到 5.2 版本之前的遗留插件。

文档告诉我使用这样的调用来从我的插件中访问另一个特定插件:

$plugin = Shopware()->Container()->get('kernel')->getPlugins()['anotherPlugin'];

不幸的是,这个 returns null 带有遗留插件,因为方法 getPlugins() returns 数组只包含为 5.2 版编写的插件(那些驻留在custom/plugins 个文件夹)。

我该如何处理这个问题?

对于旧版本,您可以从容器中检索插件:

Shopware()->Container()->get('plugins')->Backend()->NameOfYourPlugin();

或者如果是前端插件,则使用 Frontend

Core 如果它是 Shopware Core Legacy 插件。

我会建议您迁移到新结构,因为它不会长期受支持(如果 5.3 还没有的话)。