Changing the program flow or modifying data are common tasks for plugins. Shopware provides many events to subscribe to, which makes it very extendable, but also adds complexity. So, how to find the event that is right for you?
Of course, theoretical understanding helps a lot. Nevertheless, sometimes it’s not easy to decide which event to use. In these cases the Frosh Profiler comes into use, which proved to be an indispensable tool for me. The easiest way to install it is by downloading the newest release from GitHub and then uploading the zip via the plugin manager. From this point it can be handled like any other store plugin. After the installation and activation a bar is displayed at the bottom of the shop.
Now you can navigate to a specific page type, for example the product detail page, where you want to extend Shopware. In the bar you will find the item ‘Events’, which lists all called events for a certain page. Conveniently, the passed arguments and (if the event type supports it) the return values are listed for each event.
Furthermore, the events are listed in the order in which they were originally called, so if you are searching for early events, regarding e.g. routing, just take a look at the top. With this information you can start searching for suitable events to react to or modify the return values.