Prestashop custom module routing issue after update to 1.7.8.4

Viewed 354

I just updated a PrestaShop website from 1.7.8.3 to 1.7.8.4, everything worked fine, but I'm havine 404 errors on custom module routes.

On module install I register routes like:

$this->registerHook('ModuleRoutes')

And my routes are like:

public function hookModuleRoutes() {
    $urls = array(
        'module-mymodulename-posts' => array(
            'controller' => 'posts',
            'rule' => 'posts/list',
            'keywords' => array(),
            'params' => array(
                'fc' => 'module',
                'module' => 'mymodulename',
            )
        ),
        ...
    );
    return $urls;
}

Now www.mywebsite.com/posts/list returns 404.

And www.mywebsite.com/modules/mymodulename/posts works but url is not looking as good.

It all was working fine until this morning update.

Any idea on how I could get this solved ? I have nothing about routing in the release logs.

2 Answers

You have to change getHookStatusByName function in classes/Hook.php file :

 public static function getHookStatusByName($hook_name): bool
    {
        $hook_names = [];
        if (Cache::isStored('active_hooks')) {
            $hook_names = Cache::retrieve('active_hooks');
        } else {
            $sql = new DbQuery();
            $sql->select('lower(name) as name');
            $sql->from('hook', 'h');
            $sql->where('h.active = 1');
            $active_hooks = Db::getInstance()->executeS($sql);
            if (!empty($active_hooks)) {
                $hook_names = array_column($active_hooks, 'name');
                if (is_array($hook_names)) {
                    Cache::store('active_hooks', $hook_names);
                }
            }
        }

        return in_array(strtolower($hook_name), $hook_names);
    }
Related