Skip to content

Fix error when the product was delete#582

Open
W4U-TOURS wants to merge 2 commits into
PrestaShopCorp:masterfrom
W4U-TOURS:W4U-TOURS-patch-deletedproduct
Open

Fix error when the product was delete#582
W4U-TOURS wants to merge 2 commits into
PrestaShopCorp:masterfrom
W4U-TOURS:W4U-TOURS-patch-deletedproduct

Conversation

@W4U-TOURS
Copy link
Copy Markdown

@W4U-TOURS W4U-TOURS commented May 28, 2025

How to reproduce the issue

Environment

  • PrestaShop version: 1.7.x / 8.x
  • ps_facebook module version: latest
  • PHP version: 7.4+

Steps to reproduce

  1. Install and configure the ps_facebook module with Facebook Pixel
  2. Create a product in your PrestaShop catalog
  3. Make sure the product is synced with Facebook catalog
  4. Delete the product from PrestaShop admin panel
  5. Try to access the deleted product's URL directly (or from a Facebook ad/link)

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 returns false instead of an array. The module's EventDataProvider tries 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():

  • Check if id_product parameter exists
  • Load the product object
  • Validate with Validate::isLoadedObject() before proceeding
  • Only call getProductPageData() if the product is valid

This prevents the fatal error when accessing deleted product pages.

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
@W4U-TOURS W4U-TOURS requested a review from a team as a code owner May 28, 2025 10:55
@kseghair
Copy link
Copy Markdown
Contributor

Hello @W4U-TOURS and thank you for your contribution.
Please fix the CI before we can review this PR and provide clear explanation on how to reproduce the issue.

@kseghair kseghair added the waiting for author Status: Waiting for Author Feedback label Jun 3, 2025
fix PSR-12 standard
@ga-devfront
Copy link
Copy Markdown
Contributor

@W4U-TOURS CI is now fixed you can juste rebase your PR from master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting for author Status: Waiting for Author Feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants