Skip to content

Prevent fatal error when product template variable is a Product object#181

Open
boo-code wants to merge 1 commit into
PrestaShop:devfrom
boo-code:fix/footer-product-fatal-on-product-object
Open

Prevent fatal error when product template variable is a Product object#181
boo-code wants to merge 1 commit into
PrestaShop:devfrom
boo-code:fix/footer-product-fatal-on-product-object

Conversation

@boo-code

Copy link
Copy Markdown
Questions Answers
Description? HookDisplayFooterProduct::run() reads the product Smarty variable and passes it straight to ProductWrapper::prepareItemFromProduct(), which consumes it with array keys ($product['id_product'], $product['name'], …). That variable is normally a ProductLazyArray (array-accessible), but some themes/modules assign a raw Product object to it, producing a fatal error Cannot use object of type Product as array on the product page (reported on 5.0.3 / PS 8.2.4). This PR guards the hook: if the product is not array-accessible, it skips tracking instead of breaking the page. ProductLazyArray implements ArrayAccess, so the normal flow is unaffected.
Type? bug fix
BC breaks? no
Deprecations? no
Fixed ticket? Fixes #179.
How to test? On a product page where the product Smarty variable is a raw Product object, before this PR the page fatals with Cannot use object of type Product as array (ProductWrapper.php line ~136). Deterministic check: prepareItemFromProduct(new Product(1)) throws that error; with the guard, HookDisplayFooterProduct::run() returns without a fatal. With the standard ProductLazyArray (which implements ArrayAccess), tracking continues to work as before.
Sponsor company

HookDisplayFooterProduct::run() passes the 'product' Smarty variable straight
to ProductWrapper::prepareItemFromProduct(), which accesses it with array keys.
The variable is normally a ProductLazyArray (array-accessible), but some themes
or modules assign a raw Product object, causing a fatal error
"Cannot use object of type Product as array" on the product page.

Guard against a non-array-accessible product and skip tracking in that case
instead of breaking the whole product page.
@ps-jarvis

Copy link
Copy Markdown

Hello @boo-code!

This is your first pull request on ps_googleanalytics repository of the PrestaShop project.

Thank you, and welcome to this Open Source community!

@github-project-automation github-project-automation Bot moved this to Ready for review in PR Dashboard Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

Fatal error

2 participants