After improving my payment plugin the other day, I ran into an error – or so I thought.
You have requested a non-existent service service.alias
I tried to import translations for my payment method while installing the plugin. To do this, I wrote a service to read the JSON translation files and give me the important part as an array. I tried to get the service via DI container, but the error above was thrown.
My conclusion: The services of my plugin aren’t part of the DI container before the plugin is active. That means while running
Shopware\Core\Framework\Plugin::install() you can’t access your services yet. But once the plugin is installed, the services are part of the DI container while running
So there are two options:
- Use new Class() – please don’t.
- Move the logic to the activation step of your plugin