Skip to content
← All PrestaShop 9 errors

PrestaShop 9 errors

Call to undefined method addJquery() in PrestaShop 9

PrestaShop 9 removed addJquery() from controllers. Modules that still call it in a hook stop the whole page with a fatal error, even though the call had done nothing since 1.7.7.

The error
Call to undefined method ProductController::addJquery()
Removed in
PrestaShop 9.0
Usually found in
Module header hooks, module controllers

What happened

Older modules prepare their page assets with $this->context->controller->addJquery(), usually in hookDisplayHeader or hookActionFrontControllerSetMedia, to make sure jQuery is on the page before their own script.

That call has done nothing since PrestaShop 1.7.7: jQuery is always included, and the method only logged a deprecation notice. PrestaShop 9.0 removed it from the base Controller class. Now the same line is a fatal error.

Because header hooks run on every page, the error rarely stays in one corner: product pages, the cart or the whole front office show error 500. The class in the message is whichever page was opened, for example ProductController::addJquery(), IndexController::addJquery() or AdminOrdersController::addJquery().

The fix

Delete the call. jQuery is already there:

// Before
public function hookDisplayHeader()
{
    $this->context->controller->addJquery();
    $this->context->controller->registerJavascript('mymodule', 'modules/mymodule/views/js/front.js');
}

// After (works in 1.7.7, 8 and 9)
public function hookDisplayHeader()
{
    $this->context->controller->registerJavascript('mymodule', 'modules/mymodule/views/js/front.js', ['position' => 'bottom', 'priority' => 200]);
}

addJqueryUI() and addJqueryPlugin() still exist in PrestaShop 9, so lines that load a jQuery UI component or a bundled plugin can stay.

"jQuery is not defined" in a template

The other half of the same habit: a module template with an inline <script> that uses $ or jQuery. In PrestaShop 1.7 and later the theme loads jQuery at the bottom of the page (Classic bundles it into themes/core.js), so an inline script printed earlier runs before it and fails with jQuery is not defined. Adding addJquery() never fixed that.

Either move the code to a JS file registered with registerJavascript() as above, or wait for the page in the inline script:

<script>
  document.addEventListener('DOMContentLoaded', function () {
    $('.mymodule-block').addClass('ready');
  });
</script>

Where else it hides

grep -rn "addJquery()" modules/ override/ themes/

The search with the brackets finds only addJquery() itself, not addJqueryUI() or addJqueryPlugin(). For the 404 errors on old jQuery files see jquery-1.11.0.min.js 404.

Find every place like this before you upgrade

Where one removed call is, there are usually more. Our free PrestaShop 9 Readiness Check reads the code of every module, the theme and the overrides and lists each problem with its file and line. It only reads, nothing is changed.

Get the free check

Prefer not to fix it yourself? We upgrade stores to PrestaShop 9 for a fixed price. See the upgrade