Skip to content

fix: undefined placeholder method on empty gallery#3

Merged
SamJUK merged 1 commit into
masterfrom
samjuk1999/sam-44-undefined-placeholder-method
Jul 15, 2026
Merged

fix: undefined placeholder method on empty gallery#3
SamJUK merged 1 commit into
masterfrom
samjuk1999/sam-44-undefined-placeholder-method

Conversation

@SamJUK

@SamJUK SamJUK commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes crash reported in SAM-44: Call to a member function getDefaultPlaceholderUrl() on null when a product has no gallery images.

Gallery::getData('imageHelper') returns null — _imageHelper is a protected property on the block, not block data, so there's nothing under that data key. Fix injects Magento\Catalog\Helper\Image into the observer directly instead of reaching into the block.

Test plan

  • Added a unit test (testUsesPlaceholderWhenGalleryHasNoImages) that reproduces the exact crash against the old code, and passes against the fix.
  • Ran phpcs (Magento2 standard), phpstan (level 1), and full phpunit suite (42/42 passing) inside the samjuk/magento-ci-testing-env:2.4.8-p3-php8.3 container used by CI, with the module required into a full Magento install via the local path repo (mirrors _local_test_dev.sh).

Gallery::getData('imageHelper') returns null — _imageHelper is a
protected property on the block, not block data — so calling
getDefaultPlaceholderUrl() on it fatals when a product has no gallery
images. Inject Magento\Catalog\Helper\Image directly instead.
@SamJUK
SamJUK merged commit 0c3e003 into master Jul 15, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant