Fix: recursive lookup templates#380
Open
ahuininga-orisha wants to merge 2 commits into
Open
Conversation
jansentjeu
requested changes
May 15, 2026
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
TemplateFinder::forCategory(closes Performance impact because of category lookup in Model/Config/TemplateFinder.php #291). The original implementation recursively called$category->getParentCategory()to walk up the category tree, which internally callsCategoryRepository::get()— one DB query per ancestor level. On a PDP with a product in a deeply nested category this could trigger a dozen or more queries.Category::getPathIds()to extract all ancestor IDs from the already-loadedpathstring (e.g.1/2/9/10/13) — no DB call. It then loads all ancestors in one query viaCategoryCollectionFactory, selecting only the two relevant EAV attributes (tweakwise_{type}_templateandtweakwise_{type}_group_code). The ancestors are then iterated from closest to furthest to preserve the original nearest-match behaviour.declare(strict_types=1)and cleaned up imports as part of touching the file.How to test
Scenario 1 — Ancestor template is inherited
Scenario 2 — Direct category template takes priority
Scenario 3 — Product-level template takes priority over all categories
Scenario 4 — Falls back to global default when nothing is set