-
-
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]>
|
Test Results962 tests 954 ✅ 15s ⏱️ Results for commit be38022. ♻️ This comment has been updated with latest results. |
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 |
| public function isEnabledForProductDetail() | ||
| { | ||
| return Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLED); | ||
| } |
Copilot
AI
Dec 7, 2025
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.
The new isEnabledForProductDetail() method lacks caching, unlike isEnabled() which caches its result in $this->_enabled. Since this method will be called multiple times during request processing (in observers, blocks, and helpers), consider adding caching to avoid repeated getStoreConfigFlag() calls.
Suggested implementation:
protected $_enabledForProductDetail = null;
public function isEnabledForProductDetail()
{
if (is_null($this->_enabledForProductDetail)) {
$this->_enabledForProductDetail = Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLED);
}
return $this->_enabledForProductDetail;
}


Description (*)
Product detail page swatches failed to render when "Product Attribute to Use for Swatches in Product Listing" was unset, despite "Product Attributes to Show as Swatches in Product Detail" being configured. The
isEnabled()check incorrectly required both settings.Changes:
isEnabledForProductDetail()method that checks only the global enabled flagSwatches::shouldRender()- detail page swatch renderingData::getSwatchesProductJs()- detail page JavaScriptproductLoadAfter,loadChildProductImagesOnMediaLoad)Productimg::filterImageInGallery)Abstract::_toHtml)Before:
isEnabled()required listing attribute for all contextsAfter: Context-specific checks
Related Pull Requests
N/A
Fixed Issues (if relevant)
Manual testing scenarios (*)
Questions or comments
The fix maintains backward compatibility—
isEnabled()behavior unchanged for listing contexts. Product detail and listing swatches now operate independently as the configuration structure intended.Contribution checklist (*)
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.