Search code examples
phpeventshookobserver-patternprestashop

Prestashop Back-Office dynamic hooks (events) not working


Hi I'm developing a custom module for my company on Prestashop and I need some help. I've recently developed the same plugin on Magento but here I'm having some troubles with events (also called dynamic hooks).

I'm trying to use the dynamic hooks on the backend to manage product stocks. I'm not able to catch prestashop backend events on my module despite I've registered the hooks in my install() method:

function install() {
   if (parent::install() == false
    || !$this->registerHook('home')
    || !$this->registerHook('productFooter') 
    || !$this->registerHook('orderConfirmation') 
    || !$this->registerHook('shoppingCart')
    || !$this->registerHook('actionProductDelete')
    || !$this->registerHook('actionProductUpdate')) {
    return false;
}
//default configuration values
...

and placed specific methods for each one.

public function hookActionProductDelete($params) { ... }

I'm logging all the process on both sides. On my module with firePHP and FileLoggerCore and on Prestashop's core classes where events are dispatched with the prestashop's FileLoggerCore.

The events like (actionProductDelete) found on Product class are dispatched but I can not capture them.

Another point that I've noticed is that hook names change between prestashop versions. In this last version 1.5 there are a lot more hooks than in previous ones. It's possible to use same hooks in versions from 1.3 to 1.5?

Sorry for my english and many thanks in advance.


Solution

    1. check if your module is hooked in "admin > modules > positions" on actionProductDelete hook

    2. you can use old hook name for PS 1.3-1.5 compatibility, look at ps_hook_alias DB table. For hook that doesn't exist before 1.5, I think you need override for 1.4 & code modifications for 1.3