Skip to content

fix(plugin-ecommerce): pass limit 0 to variant joins so options and duplicate checks are not capped at 10 - #18509

Open
Kshot3000 wants to merge 1 commit into
payloadcms:mainfrom
Kshot3000:fix/18498-plugin-ecommerce-join-limit
Open

Kshot3000 wants to merge 1 commit into
payloadcms:mainfrom
Kshot3000:fix/18498-plugin-ecommerce-join-limit

Conversation

@Kshot3000

Copy link
Copy Markdown

Fixes #18498

What does this PR do?

plugin-ecommerce read two join fields without passing a limit, so both fell back to the database adapter's join default (field.defaultLimit ?? 10 in @payloadcms/drizzle). Past 10 rows the plugin silently worked with an incomplete list:

  1. Variant options selector — VariantOptionsSelector loaded each variant type's options join with only sort: 'value', so only the first 10 options of a type were ever offered in the admin UI.
  2. Duplicate-variant validation — validateOptions loaded the product's variants join with no limit and checked the incoming combination against product.variants.docs, so a combination already used by an 11th or later variant passed validation and could be saved twice. The selector's client-side duplicate warning (ErrorBox, fed by the same product read) had the same blind spot.

Following the issue's suggested fix, this passes an explicit limit: 0 (unbounded, already supported by the adapters) at all three call sites:

  • ui/VariantOptionsSelector/index.tsx — the variant-type options join
  • ui/VariantOptionsSelector/index.tsx — the product read feeding ErrorBox now passes joins: { variants: { limit: 0 } }
  • collections/variants/createVariantsCollection/hooks/validateOptions.ts — the sibling variants join

Related fix in the same file (called out as "minor, related" in #18498)

validateOptions looked up all four of its messages under the ecommerce: namespace (variantOptionsRequired, productRequired, variantOptionsRequiredAll, variantOptionsAlreadyExists), but the plugin registers its translations only under plugin-ecommerce: (see the merge in src/index.ts), so none of them resolved — the server logs key not found: ecommerce:variantOptionsAlreadyExists and callers only ever get the generic field error. All four keys exist in the plugin's translations, and this was the only file using the wrong prefix, so the namespace is corrected for all four.

Verification

Reproduced and verified end-to-end with the reporter's own repro repo (https://github.com/klaatu-code/payload-ecommerce-variant-limit-repro, SQLite, published @payloadcms/plugin-ecommerce 3.90.2):

  • Before: bug1=REPRODUCED bug2=REPRODUCED — selector query offers 10 of 12 options (white/yellow missing), validator compares against 10 of 11 variants, a duplicate of the oldest variant is saved, and key not found: ecommerce:variantOptionsAlreadyExists is logged.
  • After (the published package's compiled output patched with exactly these changes): the selector query returns 12/12 options, the validator compares against 11/11 siblings, the duplicate of the oldest variant is rejected by the real validateOptions hook even when the caller uses the old query, and the key not found log is gone. Control case (duplicate of a visible sibling) is rejected both before and after.

Also adds an integration test in test/plugin-ecommerce/int.spec.ts that creates a product with 11 variants and asserts a duplicate of every existing combination is rejected, cleaning up after itself (the suite shares state).

Not run locally: the monorepo integration suite (requires a full pnpm install + core build, not available in my environment) — the new test follows the suite's existing fixture/seed patterns and CI is authoritative for it. The changed files are Prettier-clean under the repo's .prettierrc.json.

Disclosure: this fix was prepared with AI assistance; all verification output above is from real runs of the reporter's repro.


Fix offered freely — tips welcome, never required: PayPal [email protected] · BTC 3GnR7TWBXAB3pPztBWpNF4LMNEX5yX8vZK · ETH 0xA1d3CEB7bD707847c3c6aB59d30D385FE8DD85Fc · SOL DLg1ua1ufewQ81J7dQomwWhXzhZreq4jEwTaQJR31Exb — GitHub @Kshot3000, X @Kshot9000

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[plugin-ecommerce] Variant options selector and duplicate-variant validation silently stop at the first 10 join results

1 participant