ilclaudio Posted August 3, 2016 Share Posted August 3, 2016 Hi all, excuse me, but I'm new to PrestaShop and I've some questions about hooks for which I've not found answers in the book I'm reading and in the Internet. Is it possible that multiple custom modules register the same hook, for example "orderConfirmation"? If it is possible, in which order are they executed? And if one of these hooks has to execute some code, without returning anything, is it right that the "run" function of the class returns an empty string? class MyModuleOrderConfirmationController{ public function run($params) { ... <some code> ... return ''; }} thank you claudio Link to comment Share on other sites More sharing options...
rocky Posted August 3, 2016 Share Posted August 3, 2016 You shouldn't be overriding the run function! You'll see this in the comment on line 166 of classes/controller/Controller.php: /** * Starts the controller process (this method should not be overridden!) */ public function run() In fact, you probably shouldn't be using a module controller at all. You should use a hook inside your module's main PHP file. Can you explain further exactly what you're trying to do? There are multiple hooks in the order process and you should choose the right one to use. Yes, multiple modules can use the same hook. The order they execute depends on the order they are listed on the Modules > Positions tab. You can change the order of modules there to change the execution order. 1 Link to comment Share on other sites More sharing options...
ilclaudio Posted August 4, 2016 Author Share Posted August 4, 2016 (edited) Thank you very much for your answer, yes the configurations of Modules > Positions tab are what I was looking for. Yes I've seen that in the modules sometimes the hook are defined as controllers and sometimes there is simply a function in the main file. However in the main file I have this: public function hookOrderConfirmation($params) { $controller = $this->getHookController('orderConfirmation'); return $controller->run($params); } That calls the file with the controller MyModuleOrderConfirmationController. When an order is confirmed I have to iterate the articles of the order and the I have to call an external API for each article, depending on same conditions. So I'm thinking of using a module attached to the orderConfirmation hook. There is already a module attached to this hook. I would attach my module after this one. claudio Edited August 4, 2016 by ilclaudio (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now