Prevent fatal error when product template variable is a Product object#181
Open
boo-code wants to merge 1 commit into
Open
Prevent fatal error when product template variable is a Product object#181boo-code wants to merge 1 commit into
boo-code wants to merge 1 commit into
Conversation
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.
|
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! |
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.
HookDisplayFooterProduct::run()reads theproductSmarty variable and passes it straight toProductWrapper::prepareItemFromProduct(), which consumes it with array keys ($product['id_product'],$product['name'], …). That variable is normally aProductLazyArray(array-accessible), but some themes/modules assign a rawProductobject to it, producing a fatal errorCannot use object of type Product as arrayon 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.ProductLazyArrayimplementsArrayAccess, so the normal flow is unaffected.productSmarty variable is a rawProductobject, before this PR the page fatals withCannot use object of type Product as array(ProductWrapper.phpline ~136). Deterministic check:prepareItemFromProduct(new Product(1))throws that error; with the guard,HookDisplayFooterProduct::run()returns without a fatal. With the standardProductLazyArray(which implementsArrayAccess), tracking continues to work as before.