Fix DynamicStorage entity_type filtering to prevent CMS/product ID collision (#39996) #39997
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.
Description (*)
This pull request fixes a critical bug in
DynamicStorage::findProductRewriteByRequestPath()
where the method lacks properentity_type
filtering when querying URL rewrites.Root Cause:
The method extracts the last URL segment (e.g.,
privacy-policy-cookie-restriction-mode
from/category/privacy-policy-cookie-restriction-mode
) and queries theurl_rewrite
table without filtering byentity_type
. This causes CMS page URL rewrites to be incorrectly treated as product URL rewrites.The Problem:
When a CMS page and product have coincidental matching entity IDs, and the product exists in the target category, malformed URLs like
/category/cms-page-identifier
incorrectly resolve to/cms/page/view/page_id/X/category/Y
instead of returning a 404.The Fix:
Added
$data[UrlRewrite::ENTITY_TYPE] = 'product';
before the database query to ensure only product URL rewrites are processed by this method.Related Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
Setup Prerequisites:
test-category
(note the category entity_id, e.g., ID=48)test-cms-page
(note the CMS page entity_id, e.g., ID=4)bin/magento indexer:reindex && bin/magento cache:flush
Test the Bug (Before Fix):
/test-category/test-cms-page
Test the Fix (After Fix):
bin/magento cache:flush
/test-category/test-cms-page
Verify Normal Product URLs Still Work:
/test-category/actual-product-url
Verify CMS Pages Still Work:
/test-cms-page
(direct CMS page URL)Questions or comments
This is a minimal, surgical fix that addresses the root cause without affecting any other functionality. The change only adds proper entity_type filtering where it was missing, ensuring DynamicStorage only processes actual product URL rewrites as intended.
The fix has been tested extensively and resolves the issue while maintaining backward compatibility for all legitimate URL patterns.
Contribution checklist (*)