Fix error when the product was delete#582
Open
W4U-TOURS wants to merge 2 commits into
Open
Conversation
Fix PHP Fatal error: Uncaught TypeError: ProductControllerCore::addProductCustomizationData(): Argument PrestaShopCorp#1 ($product_full) must be of type array, bool given when accessing a product page of a deleted product
Contributor
|
Hello @W4U-TOURS and thank you for your contribution. |
fix PSR-12 standard
Contributor
|
@W4U-TOURS CI is now fixed you can juste rebase your PR from |
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.
How to reproduce the issue
Environment
Steps to reproduce
Current behavior (bug)
PHP Fatal error: Uncaught TypeError: ProductControllerCore::addProductCustomizationData():
Argument #1 ($product_full) must be of type array, bool given
Expected behavior
The page should handle the deleted product gracefully (show 404 or redirect).
Root cause
When
ProductControllerCore::getTemplateVarProduct()is called for a deleted product, it returnsfalseinstead of an array. The module'sEventDataProvidertries to use this value without checking if the product exists, causing a TypeError.Solution implemented
Added validation to check if the product exists and is loaded before calling
getProductPageData():id_productparameter existsValidate::isLoadedObject()before proceedinggetProductPageData()if the product is validThis prevents the fatal error when accessing deleted product pages.