Hi all,
I am working on a plugin, that we are upgrading to make it work on 8.x of PrestaShop, up from 1.7.8.
The app itself seems to mostly be working, however one thing I have noticed is that is fails to register any of the Hooks for our plugin. This breaks the core functionality of our plugin.
Our code is the following;
public function install() { Logger::addLog('Installing tabs', 2); $this->installTab(); Logger::addLog('calling parent::install() and registering hooks', 2); $this->registerHooks(); Logger::addLog('Registered Hooks and returning parent::install', 2); return parent::install(); }
private function registerHooks() { Logger::addLog('in registerHooks', 2); $common_hooks = array( 'displayOrderConfirmation', 'displayHeader', 'postUpdateOrderStatus', 'displayBackOfficeHeader' ); $hooks_v17 = array('displayBeforeBodyClosingTag', 'filterProductSearch'); // v1.7 + $hooks_v16 = array('displayFooter'); // v1.6 and older $hooks = array_merge($common_hooks, version_compare(_PS_VERSION_, '1.7', '<') ? $hooks_v16 : $hooks_v17); foreach ($hooks as $hook) { Logger::addLog('Register the hook ' . $hook, 2); if (!Hook::getIdByName($hook)) { Logger::addLog('module: ' . $hook . ' hook was not found', 2); return false; } $res = $this->registerHook($hook); Logger::addLog('Result of registering hook ' . $res, 2); if (!$res) { Logger::addLog('module: Failed to register ' . $hook . ' hook', 2); return false; } } // This hook is not listed in hooks table, therefore we just register it without a check if ($this->registerHook('actionOrderHistoryAddAfter') === null) { Logger::addLog('module: Failed to register actionOrderHistoryAddAfter hook', 2); } return true; }
The logs I am seeing are:
- calling parent::install() and registering hooks
- in registerHooks
- Register the hook displayHeader
- Result of registering hook
- module: Failed to register displayHeader hook
- Registered Hooks and returning parent::install
Upon installing, there are no hooks that are registered correctly. There is no `displayHeader` hook being registered.
Side note; I am also seeing intermittently an error when uploading the package into our PrestaShop store, it fails, then succeeds, then fails with the message:
"Installation of module X failed. Unfortunately, the module did not return additional details."
Looking in the Apache error_log, the only error I can see is this:
"Got error 'PHP message: PHP Notice: Unknown: file created in the system's temporary directory in Unknown on line 0', referer: https://<prestashop-store>.com/administration/index.php/improve/modules/manage?_token=<token"
If anyone has any ideas, would be grateful.
I'm not sure on the easiest way to debug this - I'm new to PHP, but can't see any return type/reason for the hooks failing to register.
One thing that is interesting that I have found is this thread:
It says that in V8, PrestaShop handles Hook errors where there are no methods implemented for it. But I have one implemented?
I've tried;
- Going through all the upgrade deprecations between 1.7.8 to 8.X and checking we don't hit any of them
- Just trying to register one hook, and not returning false.
- Split out return parent::install() && $this->registerHooks(); into 2 lines.
- Testing done on a Bitnami PrestaShop 8.1.7 store.
Thanks in advance