Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 22, 2025

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, causing isEnabled() to return false. This prevented product detail swatches from loading their JavaScript and rendering properly.

Changes Made

  • Modified getSwatchesProductJs() in Helper/Data.php to check CONFIG_PATH_ENABLED directly
  • Updated shouldRender() in Block/Catalog/Product/View/Type/Configurable/Swatches.php to check config directly
  • Override _toHtml() in Block/Catalog/Media/Js/Product.php to bypass parent's isEnabled() check
  • Added comprehensive comments explaining the decoupling
  • Code review completed and feedback addressed
  • Security checks passed
  • Fixed PHPStan error by replacing empty() with strict array comparison

Testing

  • Product detail swatches now work when listing attribute is "-- Please Select --"
  • Product listing functionality still requires listing attribute (unchanged behavior)
  • The explicit selection of "-- Please Select --" now behaves the same as having no listing attribute configured
Original prompt

This section details on the original issue you should resolve

<issue_title>[BUG] Swatches malfunction when "-- Please Select --" is explicitly chosen for listing attribute</issue_title>
<issue_description>### Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Prerequisites

When "Product Attribute to Use for Swatches in Product Listing" is explicitly set to "-- Please Select --" (empty selection), swatches display on the product detail page but don't function when clicked. The hidden select value doesn't update, causing "Please specify the product's option(s)" error on add to cart.

Expected Behavior

The explicit selection of "-- Please Select --" should behave the same as having no listing attribute configured. Product detail swatches should function independently.

Steps To Reproduce

  1. Enable Configurable Swatches
  2. Set "Product Attributes to Show as Swatches in Product Detail" to an attribute (e.g., Size)
  3. Explicitly set "Product Attribute to Use for Swatches in Product Listing" to "-- Please Select --"
  4. View configurable product page
  5. Click a swatch option
  6. Click "Add to Cart"
  7. Error: "Please specify the product's option(s)"

Environment

- OpenMage: latest
- php: 8.4

Anything else?

Workaround

Select any attribute (even unused) in the listing field instead of "-- Please Select --".

Technical Notes

The issue is specific to the empty string value when "-- Please Select --" is chosen, versus null/undefined when the field is left unconfigured. Related to getSwatchAttributeId() handling in Helper/Productlist.php.</issue_description>

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


💡 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.

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

Test Results

966 tests  ±0   958 ✅ ±0   16s ⏱️ ±0s
213 suites ±0     8 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 2f4276f. ± Comparison against base commit b74526a.

@github-actions
Copy link
Contributor

Test Results

966 tests  ±0   958 ✅ ±0   15s ⏱️ -1s
213 suites ±0     8 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 2f4276f. ± Comparison against base commit b74526a.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 22, 2025

Test Results

970 tests  ±0   962 ✅ ±0   17s ⏱️ -1s
214 suites ±0     8 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 8b171b3. ± Comparison against base commit 0ff7816.

♻️ This comment has been updated with latest results.

Copy link
Contributor Author

Copilot AI commented Jan 16, 2026

@copilot - Fix the PHP Stan error

...

Fixed in f5455fd. Replaced !empty($configAttrs) with $configAttrs !== [] for strict array comparison.

@OpenMage OpenMage deleted a comment from sonarqubecloud bot Jan 16, 2026
@sonarqubecloud
Copy link

@addison74 addison74 marked this pull request as ready for review January 16, 2026 10:29
Copilot AI review requested due to automatic review settings January 16, 2026 10:29
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 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 using isEnabled(), 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's isEnabled() 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

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 malfunction when "-- Please Select --" is explicitly chosen for listing attribute

2 participants