PrestaShop 8 to 9 Upgrade: Tackling 'addJquery()' Undefined Method in Backoffice
PrestaShop 8 to 9 Upgrade: Tackling 'addJquery()' Undefined Method in Backoffice
Migrating your PrestaShop store to a newer, more robust version like PrestaShop 9 offers significant performance and security enhancements. However, the upgrade process, especially across major versions, can sometimes introduce unexpected challenges. A common issue faced by merchants and developers post-migration is the dreaded "undefined method" error in the backoffice, often linked to deprecated functions or module incompatibilities. This community insight, drawn from a recent PrestaShop forum discussion, delves into a specific case involving the addJquery() method and provides a clear troubleshooting path.
The Migration Challenge: 'undefined addJquery()' Error
A PrestaShop user, FPE, reported a critical backoffice error after successfully migrating their store from PrestaShop 8.2.7 to 9.1.4. While the storefront remained operational, the administrative interface displayed a runtime error indicating a call to an undefined method: ContainerAQvYfrY\LegacyControllerContextProxyB5bf0c4::addJquery(). This error was traced to line 53 of the @PrestaShop/Admin/Component/Layout/head_tag.html.twig template, specifically within a section handling the displayBackOfficeHeader hook.
Runtime Error: An exception has been thrown during the rendering of a template ("Call to undefined method ContainerAQvYfrY\LegacyControllerContextProxyB5bf0c4::addJquery()") in @PrestaShop/Admin/Component/Layout/head_tag.html.twig at line 53.
The associated Twig template comment highlighted a common pattern: modules registering on the displayBackOfficeHeader hook often use methods like addCss() and addJs() to inject assets. The error strongly suggested that a module was attempting to use an outdated or removed method (addJquery()) to include jQuery, which is no longer directly available in the controller context in PrestaShop 9 in the same manner as older versions.
Expert Diagnosis and Troubleshooting Steps
Community experts quickly identified the root cause: a module hooked into displayBackOfficeHeader was still calling $this->context->controller->addJquery(). This method, common in older PrestaShop versions, has likely been deprecated or refactored in PrestaShop 9's architectural changes, leading to the "undefined method" error.
The recommended troubleshooting steps are highly actionable:
- Deactivate Non-Native Modules: The first crucial step is to isolate the problem. Deactivate all modules that are not part of the core PrestaShop installation. Even if you believe you have no "non-PrestaShop" modules, a theme or a bundled module might be the culprit.
- Clear Cache Manually: After deactivating modules, it's paramount to clear the PrestaShop cache. This isn't just about clearing it from the backoffice (which might be inaccessible). Manually delete the contents of the
/var/cache/prodand/var/cache/devdirectories (or whatever your cache directory is named based on your environment). This ensures no old, compiled code or template files interfere. - Reactivate Modules One by One: Once the backoffice is accessible, reactivate your modules systematically. After each reactivation, clear the cache and check if the error reappears. This process will pinpoint the exact module causing the conflict.
Navigating Module Deactivation Without Admin Access
A common hurdle when the backoffice is inaccessible is how to deactivate modules. The forum thread addressed this, offering two primary methods:
- Database Modification: For advanced users, modules can be deactivated directly in the database. Locate the
ps_moduletable, find the entry for the problematic module (if known, otherwise you might need to try common third-party ones), and set itsactivecolumn to0. - Renaming Module Directories: A quicker, though less clean, method for debugging is to rename the directories of suspected third-party modules within the
/modulesfolder. This effectively makes PrestaShop unable to load them. Remember to rename them back once the culprit is identified.
To assist in distinguishing native from non-native modules, a helpful list of common PrestaShop 9.1.x native modules was provided, covering categories like Administration, Marketing, Navigation, Catalogue, Clients, and Payment. This list serves as a valuable reference during the isolation process.
The Ultimate Solution: Module Updates
Ultimately, if a third-party module or theme is identified as the source of the addJquery() error, the definitive solution is to contact its developer. The module or theme needs to be updated to be fully compatible with PrestaShop 9.x, ensuring it uses the correct and current methods for asset management, aligning with PrestaShop's evolving architecture.
At Migrate My Shop, we understand these complexities. Our expertise in PrestaShop migrations ensures that such post-upgrade issues are diagnosed and resolved efficiently, helping you maintain a smooth and functional e-commerce platform.