Registering/unregistering a module to a hook and implementing a module’s behavior on a hook execution
Even if we will study deeply the modules’ definitions later in this book, please consider that a module will be defined by a class extending the Module
class defined in the /
classes/module/Module.php
file.
When we install our module in the PrestaShop BO UI, it runs the install()
method of our Module
class. And this is precisely where we want to register our module to the hooks. It can be done with the help of the registerHook($hook_name, $shop_list = null)
method of the parent Module
class, where $hook_name
has to be the string name of the hook to register with, and $shop_list
has to be the integer array of shop IDs in the case of a multistore.
For example, if we want to register to the displayTop
hook (which enables us to display HTML content at the top of our FO pages in the header), we will simply define our install
method as follows:
public function install...