Skip to content

fix: PrestaShop 9.0 and PHP 8.1 full compatibility#332

Open
bambinounos wants to merge 3 commits intonenes25:17from
bambinounos:fix/prestashop9-php81-compatibility
Open

fix: PrestaShop 9.0 and PHP 8.1 full compatibility#332
bambinounos wants to merge 3 commits intonenes25:17from
bambinounos:fix/prestashop9-php81-compatibility

Conversation

@bambinounos
Copy link

@bambinounos bambinounos commented Feb 25, 2026

Summary

This PR makes eicaptcha fully compatible with PrestaShop 9.0.3 and PHP 8.1+, fixing fatal errors and modernizing the codebase.

Tested against

  • PrestaShop 9.0.3 (Basic Edition)
  • PHP 8.1

Changes

Fatal Error Fixes (Critical)

  • override/controllers/front/OrderController.php: Added : void return type to postProcess() — PS9's OrderControllerCore::postProcess() now declares : void, causing a Fatal error: Declaration must be compatible without this fix.
  • override/controllers/front/AuthController.php: Added : void return type to initContent() — Same issue, PS9's AuthControllerCore::initContent() declares : void.

PHP 8.1 Strict Types

  • eicaptcha.php: Replaced ~23 loose == comparisons with strict === when comparing Configuration::get() results (which always return strings).
  • override/controllers/front/AuthController.php: Replaced sizeof() with count() (sizeof is a discouraged alias).
  • override/modules/contactform/contactform.php: Same sizeof()count() fix.
  • src/Debugger.php: Fixed loose == to === for Configuration::get('PS_DISABLE_OVERRIDES').

PrestaShop 9 Compatibility

  • eicaptcha.php:
    • Removed hard $this->dependencies = ['contactform'] — the contactform module is not included by default in PS9 Basic Edition, and this dependency prevented module installation.
    • Updated ps_versions_compliancy max from _PS_VERSION_ to '9.99.99'.
    • Added hookDisplayHeader() canonical method — PS9's hook system looks for hookDisplayHeader() first and falls back to hookHeader() via alias. Adding the canonical method ensures direct dispatch without relying on the alias lookup.
    • Added Auth/RegistrationController conditions to renderHeaderV3() for proper reCAPTCHA v3 badge display on registration pages.
    • Added null check for captcha-box element in renderHeaderV3() to prevent JS errors.
  • src/Debugger.php:
    • contactform module check is now conditional: shows as "optional" for PS9+ instead of an error.
    • Override file checks are now skipped for PS 8.0+ (PS8/9 use native actionSubmitAccountBefore hook instead of overrides), showing a success message instead.
    • Fixed != to !== for strict comparison in class_index.php check.
  • src/Installer.php:
    • Added missing hook registrations for actionGetEicaptchaParams and actionValidateCaptcha.
    • Added missing install defaults for CAPTCHA_VERSION, CAPTCHA_V3_MINIMAL_SCORE, CAPTCHA_LOAD_EVERYWHERE, and CAPTCHA_ENABLE_LOGGED_CUSTOMERS.
    • Added missing uninstall cleanup for CAPTCHA_V3_MINIMAL_SCORE and CAPTCHA_LOAD_EVERYWHERE.
    • Default CAPTCHA_USE_AUTHCONTROLLER_OVERRIDE to '0' on PS 8.0+ (uses native hooks).

JavaScript — Remove jQuery Dependency

PS9 does not guarantee jQuery in the front-office (custom themes like Hummingbird don't include it). All JS files have been rewritten to vanilla JavaScript:

  • views/js/admin.js: $(document).ready()document.addEventListener('DOMContentLoaded')
  • views/js/eicaptcha-contact-form-v2.js: jQuery .append()document.createElement() + appendChild()
  • views/js/eicaptcha-contact-form-v3.js: Same vanilla JS rewrite for hidden input injection.

Template Fixes

  • views/templates/admin/debug.tpl: Replaced deprecated Smarty |@count modifier with count() function syntax.

Dependency Updates

  • composer.json:
    • PHP requirement: >=5.6>=8.0 (PS9 requires PHP 8.1+)
    • google/recaptcha: ~1.1^1.2 (installs latest 1.3.1, with full reCAPTCHA v3 support and PHP 8 compatibility)
  • composer.lock: Updated accordingly (google/recaptcha 1.2.4 → 1.3.1).

Important Note for PS9 Users

⚠️ If the reCAPTCHA badge does not appear after installing this module, check the following PrestaShop configuration:

SELECT value FROM ps_configuration WHERE name = 'PS_DISABLE_NON_NATIVE_MODULE';

If the value is 1, PrestaShop is silently blocking all non-native modules from executing hooks (including eicaptcha). This setting is sometimes enabled during PS upgrades or in "safe mode".

Fix: Set it to 0 via SQL or in the admin panel (Advanced Parameters → Performance → Disable non PrestaShop modules → No):

UPDATE ps_configuration SET value = '0' WHERE name = 'PS_DISABLE_NON_NATIVE_MODULE';

Then clear the cache (var/cache/prod/* and var/cache/dev/*).


Files Changed (12)

File Changes
eicaptcha.php Remove contactform dep, update compliancy, strict comparisons, add hookDisplayHeader(), fix renderHeaderV3()
composer.json PHP >=8.0, google/recaptcha ^1.2
composer.lock Updated lock file
override/controllers/front/OrderController.php Add : void return type
override/controllers/front/AuthController.php Add : void, count(), ===
override/modules/contactform/contactform.php sizeof()count()
src/Installer.php Register missing hooks, add install defaults
src/Debugger.php PS9-aware checks, strict comparisons
views/js/admin.js Vanilla JS rewrite
views/js/eicaptcha-contact-form-v2.js Vanilla JS rewrite
views/js/eicaptcha-contact-form-v3.js Vanilla JS rewrite
views/templates/admin/debug.tpl Fix deprecated @count

Test plan

  • Module installs without errors on PrestaShop 9.0.x
  • Module configuration page loads and saves correctly in admin
  • reCAPTCHA v2 displays on account registration form
  • reCAPTCHA v3 displays on account registration form
  • reCAPTCHA v2 displays on contact form (if contactform module installed)
  • reCAPTCHA v3 displays on contact form (if contactform module installed)
  • reCAPTCHA v3 badge appears on all pages when "Load everywhere" is enabled
  • Captcha validation blocks invalid submissions
  • No JavaScript console errors on front-office pages
  • Debug panel works correctly in module configuration
  • Newsletter captcha works (if ps_emailsubscription >= 2.6.0)
  • Backward compatible with PrestaShop 1.7.x / 8.x
  • Verify PS_DISABLE_NON_NATIVE_MODULE is 0 if hooks don't fire

🤖 Generated with Claude Code

Importadora Hellbam S.A. and others added 3 commits February 25, 2026 18:34
- Add void return types to controller overrides (Fatal Error fix)
- Replace loose == comparisons with strict === for Configuration::get()
- Replace sizeof() with count()
- Rewrite JavaScript files to vanilla JS (remove jQuery dependency)
- Fix deprecated Smarty |@count modifier in debug.tpl
- Remove hard dependency on contactform module (optional in PS9)
- Update ps_versions_compliancy max to 9.99.99
- Update composer.json: PHP >=8.0, google/recaptcha ^1.2
- Update Debugger: conditional checks for PS9 (overrides, contactform)
- Register missing hooks: actionGetEicaptchaParams, actionValidateCaptcha

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add Auth/RegistrationController to renderHeaderV3() conditions
  so the reCAPTCHA v3 API loads on registration pages via header
- Add null check for captcha-box element in v3 inline JS to prevent
  TypeError on pages without a form (LOAD_EVERYWHERE scenario)
- Add missing install defaults: CAPTCHA_VERSION, CAPTCHA_V3_MINIMAL_SCORE,
  CAPTCHA_LOAD_EVERYWHERE (were never initialized causing false-y values)
- Add missing uninstall cleanup for V3_MINIMAL_SCORE and LOAD_EVERYWHERE

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PrestaShop 9's hook system calls hookDisplayHeader() as the primary
method for the displayHeader hook. While the alias fallback system
maps to hookHeader(), adding the canonical method name ensures direct
dispatch without relying on the alias lookup mechanism.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant