Executing a hook
As we explained before, we can use hooks to customize our shop and we can register modules to them to trigger our customized behavior. We know how to register, unregister, and define the custom behavior inside the module definition. To get the full scope, we now need to see how to execute a hook in the shop, making the module triggers possible.
Hooks can be executed anywhere in the code of PrestaShop, from legacy to Symfony controllers, and from Smarty to Twig themed templates.
Executing a hook from a legacy controller
Any legacy controller can use the static
method named exec()
from the Hook
object. You can find its definition in the /classes/Hook.php
file. We commonly use it as follows:
Hook::exec($hook_name, $params =
array())
This includes $hook_name
(the string name of the hook to execute) and $params
(an array containing the necessary objects for good use of the hook).
For example, if you go to the /classes/controller/Controller.php
legacy controller...