Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 7, 2025

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:

  • Added isEnabledForProductDetail() method that checks only the global enabled flag
  • Updated product detail rendering to use context-appropriate check:
    • Swatches::shouldRender() - detail page swatch rendering
    • Data::getSwatchesProductJs() - detail page JavaScript
  • Updated shared components to support both contexts independently:
    • Observer methods (productLoadAfter, loadChildProductImagesOnMediaLoad)
    • Image filtering (Productimg::filterImageInGallery)
    • Media JS blocks (Abstract::_toHtml)

Before: isEnabled() required listing attribute for all contexts

public function isEnabled()
{
    return Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLED)
        && Mage::helper('configurableswatches/productlist')->getSwatchAttributeId();
}

After: Context-specific checks

// For product listing
public function isEnabled() { /* unchanged */ }

// For product detail (new)
public function isEnabledForProductDetail()
{
    return Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLED);
}

Related Pull Requests

N/A

Fixed Issues (if relevant)

  • Fixes issue where swatches don't appear on product detail page when listing attribute is unset

Manual testing scenarios (*)

  1. Navigate to System > Configuration > Catalog > Configurable Swatches
  2. Set "Enabled" to "Yes"
  3. Select an attribute (e.g., "Size") in "Product Attributes to Show as Swatches in Product Detail"
  4. Leave "Product Attribute to Use for Swatches in Product Listing" unset (-- Please Select --)
  5. View a configurable product detail page
  6. Verify swatches render correctly for the configured attribute
  7. Optionally set the listing attribute and verify listing pages also work

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 (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)
Original prompt

This section details on the original issue you should resolve

<issue_title>[BUG] Swatches Not Displaying Correctly on Product Page</issue_title>
<issue_description>### Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

I have encountered a bug with the swatches for configurable products in the latest version, which I believe needs attention. The issue occurs when trying to display the swatches (such as color or size) on the product page.

When "Size" is not selected in the "Product Attribute to Use for Swatches in Product Listing" field, the swatches do not appear on the product page. Instead, the attribute remains as a regular dropdown.

Expected Behavior

Swatches should appear on the product page regardless of the setting for "Product Attribute to Use for Swatches in Product Listing", since displaying swatches in the product detail page is not related to how products are listed in the category or the product listing configuration.

I consider this is a bug, as the swatches should be independent of the listing configuration and should display properly on the product detail page regardless of the "Product Attribute to Use for Swatches in Product Listing" setting.

Steps To Reproduce

  1. Select "Size" as an attribute in the "Product Attributes to Show as Swatches in Product Detail" section.

  2. Ensure that "Size" is not selected for "Product Attribute to Use for Swatches in Product Listing".

  3. View the product page.

Environment

- OpenMage: latest from the cloned repo
- PHP: 8.4

Anything else?

Visual Comparison

Without Size selected in Product Listing

Image

With Size selected in Product Listing

Image

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@github-actions github-actions bot added the Component: ConfigurableSwatches Relates to Mage_ConfigurableSwatches label Dec 7, 2025
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
Copilot AI requested a review from addison74 December 7, 2025 20:43
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 7, 2025

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2025

Test Results

962 tests   954 ✅  15s ⏱️
211 suites    8 💤
  1 files      0 ❌

Results for commit be38022.

♻️ This comment has been updated with latest results.

@addison74 addison74 marked this pull request as ready for review December 7, 2025 20:57
Copilot AI review requested due to automatic review settings December 7, 2025 20:57
Copy link
Contributor

Copilot AI left a 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

Comment on lines +53 to +56
public function isEnabledForProductDetail()
{
return Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLED);
}
Copy link

Copilot AI Dec 7, 2025

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;
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: ConfigurableSwatches Relates to Mage_ConfigurableSwatches

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Swatches Not Displaying Correctly on Product Page

2 participants