Shopware 6: (No) services on plugin install

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 Shopware\Core\Framework\Plugin::activate()

So there are two options:

  1. Use new Class() – please don’t.
  2. Move the logic to the activation step of your plugin

Leave a Reply

Discover more from Winkelwagen

Subscribe now to keep reading and get access to the full archive.

Continue reading