Fix product detail swatches when listing attribute is "-- Please Select --"#5187
Open
Fix product detail swatches when listing attribute is "-- Please Select --"#5187
Conversation
Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com>
Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix swatches malfunction with empty listing attribute
Fix product detail swatches when listing attribute is "-- Please Select --"
Dec 22, 2025
Contributor
Contributor
Contributor
Co-authored-by: addison74 <8360474+addison74@users.noreply.github.com>
Contributor
Author
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where product detail page swatches malfunction when "Product Attribute to Use for Swatches in Product Listing" is explicitly set to "-- Please Select --". The fix decouples product detail swatches from the listing attribute requirement.
Changes:
- Modified
getSwatchesProductJs()to check config directly instead of usingisEnabled(), ensuring product detail JavaScript loads independently - Updated
shouldRender()to use direct config check, removing dependency on listing attribute - Overrode
_toHtml()in Product block to bypass parent'sisEnabled()check that requires listing attribute
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| app/code/core/Mage/ConfigurableSwatches/Helper/Data.php | Modified getSwatchesProductJs() to check config flag directly and validate swatch attributes exist before loading JavaScript |
| app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Product/View/Type/Configurable/Swatches.php | Updated shouldRender() to check config directly without requiring listing attribute |
| app/code/core/Mage/ConfigurableSwatches/Block/Catalog/Media/Js/Product.php | Added _toHtml() override to check config directly and call grandparent to skip Abstract class's isEnabled() check |
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 Malfunction When Listing Attribute is "-- Please Select --"
Summary
Fixed an issue where product detail swatches don't function when "Product Attribute to Use for Swatches in Product Listing" is explicitly set to "-- Please Select --" (empty selection).
Root Cause
The
isEnabled()method requires both ConfigSwatches to be enabled AND a listing attribute to be configured. When "-- Please Select --" is explicitly chosen,getSwatchAttributeId()returns an empty string, causingisEnabled()to return false. This prevented product detail swatches from loading their JavaScript and rendering properly.Changes Made
getSwatchesProductJs()inHelper/Data.phpto checkCONFIG_PATH_ENABLEDdirectlyshouldRender()inBlock/Catalog/Product/View/Type/Configurable/Swatches.phpto check config directly_toHtml()inBlock/Catalog/Media/Js/Product.phpto bypass parent'sisEnabled()checkempty()with strict array comparisonTesting
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.