[Backport to release/10.6] Add to Cart: improve validation of attributes with multi-word names#63647
Conversation
…63640) * Improve attributes validation for two words cases * Add changelog * Cover one more case missing normalization * Update chaneglog * Refactor normalisation so it's more centralised * Add tests * Fix lint
Testing GuidelinesHi @kmanijak , Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed. Reminder: PR reviewers are required to document testing performed. This includes:
|
Test using WordPress PlaygroundThe changes in this pull request can be previewed and tested using a WordPress Playground instance. Test this pull request with WordPress Playground. Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit. |
|
Size Change: +37 B (0%) Total Size: 5.97 MB |
There was a problem hiding this comment.
Tested and multi-word named attributes are enabled correctly and can be added to cart.
I only could experience the problem from this PR: #63535 that's fixed on trunk but not in 10.6.
Product is still added to cart but with console error and downgraded UX but that's out of scope of this particular fix hence approving and merging.
FYI @SantosGuillamot
This PR is a cherry-pick of #63640 to
release/10.6.Original PR Description
Submission Review Guidelines:
Changes proposed in this Pull Request:
Fixes attribute options being incorrectly disabled in the Add to Cart with Options block for variable products whose attribute slugs contain hyphens.
Root cause: The PHP context passes attribute names as slugs (e.g., attribute_pa_some-name), which normalizes to some-name. The Store API returns attribute labels with spaces (e.g., some name). The strict comparison "some-name" === "some name" failed, causing
getVariationAttributeValueto returnundefinedand all options for that attribute to appear disabled.Fix: Updated
normalizeAttributeName()inattribute-matching.tsto also replace hyphens with spaces, and ensured all comparison points in the file use the normalized form consistently.Closes #63635
(For Bug Fixes) Bug introduced in PR #62880
Screenshots or screen recordings:
How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
numeric-sizetrunkTesting that has already taken place:
Milestone
Automatically assign milestone for the next WooCommerce versionChangelog entry
Automatically create a changelog entry from the details below.This Pull Request does not require a changelog entry. (Comment required below)Changelog Entry Details
Significance
Type
Message
Changelog Entry Comment
Comment