-
-
Notifications
You must be signed in to change notification settings - Fork 449
Fix: Decouple product detail swatches from listing attribute requirement #5137
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]>
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 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 |
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
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Co-authored-by: addison74 <[email protected]>
Co-authored-by: addison74 <[email protected]>
Co-authored-by: addison74 <[email protected]>
Co-authored-by: addison74 <[email protected]>
|
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 <[email protected]>
Co-authored-by: addison74 <[email protected]>
Co-authored-by: addison74 <[email protected]>
|



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.