You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ecommerce plugin validates that no two variants of a product use the same options combination. The check in validateOptions loads the product's variants join with findByID without draft: true, so it compares against the other variants' published options. Variants have drafts, and changes saved as a draft don't touch the published values.
So when a variant's options are corrected in a draft, its old combination still counts as taken. Creating variants, fixing their options as drafts, and then publishing them one by one fails with "This variant combo is already in use by another variant", although no variant uses that combination any more. The variant stays unpublished until the other variant is published first.
The check should read the latest drafts. Note that with draft: true the join's id: { not_equals: data.id } filter no longer excludes the variant being validated (at least on SQLite), so that variant then has to be excluded from the results by ID instead. Otherwise it is compared with itself and every publish is rejected.
This affects both v3 and v4: the same code ships in 4.0.0-beta.4 and is on main.
Clone this repo and open the variant-duplicate-check-ignores-drafts/ directory
pnpm install
pnpm test:int: the test publishes variant A with the option "Small", changes A to "Large" in a draft, creates variant B as a draft with "Small", and publishes B.
Publishing B is rejected:
× compares against the latest draft of the other variants' options
AssertionError: promise rejected "ValidationError: The following field is invalid: Variant options" instead of resolving
Activity
fix: address six more Payload v4 database and ecommerce issues [skip ci]