Search code examples
shopwareshopware6

Easiest way to run code in Shopware6 framework / context


While developing a shopware6 module, I sometimes want to test a few lines of code, to see if I'm moving the right direction. Let's say I want to run the following code (ignoring that I would use xDebug)

$container = $kernel->getContainer();
$customRepository = $container->get('foobar.repository');
...
var_dump($customId); die();

How / Where can I incorporate that without creating too much of an overhead, and without altering anything in /vendor? I tried it in index.php, but as soon as we have the framework loaded, there a re already several paths that can be taken.

Thanks


Solution

  • Create a custom plugin, with a Command class. There is a good guide here, and it includes a link to the Symfony docs, and a github repo with sample code.

    I would recommend installing the plugin with the bin/console plugin:etc type commands - you get much better error reporting than if you do it via the web interface.