Skip to content

Fix swatch-renderer.js #39924

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

Open
wants to merge 1 commit into
base: 2.4-develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ define([
swatchOptions.each(function (key, value) {
let optionId = $(value).data('option-id');

if (!salableProducts.hasOwnProperty(optionId)) {
if (salableProducts != undefined && salableProducts.length > 0 && !salableProducts.hasOwnProperty(optionId)) {
Copy link
Preview

Copilot AI May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added salableProducts.length > 0 check assumes salableProducts is an array and will skip disabling options when it's an object (empty or not). Instead, guard only against undefined and then check properties, e.g.: if (salableProducts && !salableProducts.hasOwnProperty(optionId)) { … }.

Suggested change
if (salableProducts != undefined && salableProducts.length > 0 && !salableProducts.hasOwnProperty(optionId)) {
if (salableProducts && !salableProducts.hasOwnProperty(optionId)) {

Copilot uses AI. Check for mistakes.

$(value).attr('disabled', true).addClass('disabled');
}
});
Expand Down