-
-
Notifications
You must be signed in to change notification settings - Fork 450
Fix product detail swatches when listing attribute is "-- Please Select --" #5187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: addison74 <[email protected]>
Co-authored-by: addison74 <[email protected]>
Co-authored-by: addison74 <[email protected]>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |



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.