fix: PrestaShop 9.0 and PHP 8.1 full compatibility#332
Open
bambinounos wants to merge 3 commits intonenes25:17from
Open
fix: PrestaShop 9.0 and PHP 8.1 full compatibility#332bambinounos wants to merge 3 commits intonenes25:17from
bambinounos wants to merge 3 commits intonenes25:17from
Conversation
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Changes
Fatal Error Fixes (Critical)
override/controllers/front/OrderController.php: Added: voidreturn type topostProcess()— PS9'sOrderControllerCore::postProcess()now declares: void, causing aFatal error: Declaration must be compatiblewithout this fix.override/controllers/front/AuthController.php: Added: voidreturn type toinitContent()— Same issue, PS9'sAuthControllerCore::initContent()declares: void.PHP 8.1 Strict Types
eicaptcha.php: Replaced ~23 loose==comparisons with strict===when comparingConfiguration::get()results (which always return strings).override/controllers/front/AuthController.php: Replacedsizeof()withcount()(sizeof is a discouraged alias).override/modules/contactform/contactform.php: Samesizeof()→count()fix.src/Debugger.php: Fixed loose==to===forConfiguration::get('PS_DISABLE_OVERRIDES').PrestaShop 9 Compatibility
eicaptcha.php:$this->dependencies = ['contactform']— the contactform module is not included by default in PS9 Basic Edition, and this dependency prevented module installation.ps_versions_compliancymax from_PS_VERSION_to'9.99.99'.hookDisplayHeader()canonical method — PS9's hook system looks forhookDisplayHeader()first and falls back tohookHeader()via alias. Adding the canonical method ensures direct dispatch without relying on the alias lookup.renderHeaderV3()for proper reCAPTCHA v3 badge display on registration pages.captcha-boxelement inrenderHeaderV3()to prevent JS errors.src/Debugger.php:actionSubmitAccountBeforehook instead of overrides), showing a success message instead.!=to!==for strict comparison in class_index.php check.src/Installer.php:actionGetEicaptchaParamsandactionValidateCaptcha.CAPTCHA_VERSION,CAPTCHA_V3_MINIMAL_SCORE,CAPTCHA_LOAD_EVERYWHERE, andCAPTCHA_ENABLE_LOGGED_CUSTOMERS.CAPTCHA_V3_MINIMAL_SCOREandCAPTCHA_LOAD_EVERYWHERE.CAPTCHA_USE_AUTHCONTROLLER_OVERRIDEto'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|@countmodifier withcount()function syntax.Dependency Updates
composer.json:>=5.6→>=8.0(PS9 requires PHP 8.1+)~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 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
0via SQL or in the admin panel (Advanced Parameters → Performance → Disable non PrestaShop modules → No):Then clear the cache (
var/cache/prod/*andvar/cache/dev/*).Files Changed (12)
eicaptcha.phphookDisplayHeader(), fixrenderHeaderV3()composer.jsoncomposer.lockoverride/controllers/front/OrderController.php: voidreturn typeoverride/controllers/front/AuthController.php: void,count(),===override/modules/contactform/contactform.phpsizeof()→count()src/Installer.phpsrc/Debugger.phpviews/js/admin.jsviews/js/eicaptcha-contact-form-v2.jsviews/js/eicaptcha-contact-form-v3.jsviews/templates/admin/debug.tpl@countTest plan
PS_DISABLE_NON_NATIVE_MODULEis0if hooks don't fire🤖 Generated with Claude Code