Fix PHP 8.5 ErrorException when creating a new product (null getById) - #70
Merged
Merged
Conversation
Guard the translation-stores form modifier against a missing product id so getById() is never called with null. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
rhoerr
requested review from
a team,
SamueleMartini and
dadolun95
as code owners
July 14, 2026 03:06
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.
Summary
Fixes mage-os/mageos-magento2#289 — creating a new product in the admin throws an
ErrorExceptionunder PHP 8.5:Root cause
The stack trace lands in
Magento\Catalog\Model\ProductRepository::getById(), but thenulloriginates in this module's product-form modifier:TranslationStores::modifyMeta→customizeTranslationStoresList→getTranslationStores()called:On the Add Product form there is no
idrequest param, sogetParam("id")returnsnull.getById(null)then usesnullas an array offset internally ($this->instancesById[null][...]), which is a deprecation-turned-ErrorExceptionin developer mode on PHP 8.5. The surroundingtry/catchonly caughtNoSuchEntityException, so it escaped.Fix
Return early when there is no product id (a new product has no assigned stores to translate), and cast the id to
intfor the load. This mirrors the guard the module already uses for the CMS-block button (!getParam('block_id')), which is why that path was never affected.Tests
Adds
Test/Unit/.../TranslationStoresTest.php:getById()is never called for a new product (noidparam)getById()is called with the id cast tointfor an existing productVerified the test fails with the fix reverted and passes with it.
Notes
[2.1.3]).🤖 Generated with Claude Code