OpenCart: hook module to all pages

I needed to make my module appear on all pages by default in OpenCart. The layout/route system was kinda tricky and it looked like the user needs to do it manually after installing the module.

What I did was check what parameters are sent when a module gets hooked to every route and what happens afterwards. Then I added a piece of code to the install() function of my module that mirrors that behavior without user needing to do it all manually.

You'll need to load the setting model, replace modulename with the actual name of your module and change the position to the one you need. I wanted to hook it to content_top.

For 1.5.0.x
[raw]

[/raw]

For 1.5.1.x
[raw]

[/raw]
That should do it.

 

UPD:

This works for default layouts (ids 1-11). If you've got custom layouts in your installation, you'll want to retrieve corresponding layout ids from the layout table instead.