Fix: Decouple product detail swatches from listing attribute requirement#5137
Open
Fix: Decouple product detail swatches from listing attribute requirement#5137
Conversation
Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix swatches not displaying correctly on product page
Fix: Decouple product detail swatches from listing attribute requirement
Dec 7, 2025
Contributor
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where product detail page swatches failed to render when the "Product Attribute to Use for Swatches in Product Listing" configuration was unset. The fix introduces a new isEnabledForProductDetail() method that only checks the global enabled flag, decoupling product detail swatches from the listing attribute requirement. The architecture now correctly treats listing and detail page swatches as independent features, each with their own appropriate enable checks.
Key Changes
- Added
isEnabledForProductDetail()method to check only the global enabled flag without requiring listing attribute configuration - Updated product detail contexts (Swatches block and JavaScript) to use the new context-specific method
- Modified shared components (observers, image filtering, media blocks) to use OR logic, supporting both listing and detail contexts independently
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
app/code/core/Mage/ConfigurableSwatches/Helper/Data.php |
Added isEnabledForProductDetail() method and updated documentation; modified getSwatchesProductJs() to use the new method for detail page context |
app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Product/View/Type/Configurable/Swatches.php |
Changed shouldRender() to use isEnabledForProductDetail() for proper detail page swatch rendering |
app/code/core/Mage/ConfigurableSwatches/Model/Observer.php |
Updated productLoadAfter() and loadChildProductImagesOnMediaLoad() with OR logic to support both listing and detail contexts |
app/code/core/Mage/ConfigurableSwatches/Helper/Productimg.php |
Modified filterImageInGallery() with OR logic to work in both contexts |
app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Media/Js/Abstract.php |
Updated _toHtml() with OR logic to render for both listing and detail pages |
Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com>
Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com>
addison74
requested changes
Dec 22, 2025
Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com>
addison74
requested changes
Dec 22, 2025
Contributor
|
LGTM |
Add null checks before calling methods on $listSwatchAttr to prevent fatal errors when no product listing attribute is configured. This was a pre-existing bug that was exposed when product detail swatches were decoupled from listing requirements. Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com>
Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com>
Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com>
|
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.



Fix Swatches Display on Product Detail Page
isEnabled()incorrectly requires listing attribute for all contextsisEnabledForProductDetail()that only checks general enabled flag and detail attributesshouldRender()in Swatches block to use new methodgetSwatchesProductJs()to use new methodisEnabledForProductDetail()method to avoid repeatedgetStoreConfigFlag()callsnull|boolfor PHP CS Fixer complianceSummary
Successfully fixed the bug where swatches would not display on product detail pages unless a listing attribute was configured. The fix introduces
isEnabledForProductDetail()with caching to separate product detail and listing concerns, allowing swatches to work independently on each page type as originally intended by the configuration structure. Also fixed a critical bug that caused fatal errors when the listing attribute was not configured.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.