bug(plugin-ecommerce): variant title ignores drafts and goes stale
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 58/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- node.js, typescript
Research direction
Read packages/plugin-ecommerce/src/collections/variants/createVariantsCollection/hooks/beforeChange.ts and the variant title field in packages/plugin-ecommerce/src/collections/variants/createVariantsCollection/index.ts; then trace the products collection hooks for a place to update existing variants when a product title changes. Run the reproduction's pnpm test:int tests first. Done when all three cases pass: draft product titles are used, existing variant titles update after a rename, and the generated title field is read-only.
Written by the indexing model from the issue text.
Description
Describe the Bug
The ecommerce plugin generates variant titles as <product title> — <option labels> in the variants collection's beforeChange hook. The title is used as the variant's useAsTitle, so it is what editors see in the admin panel, and it goes stale or wrong in three ways:
- It uses the published product, not the latest draft. The hook loads the product with
findByIDwithoutdraft: true. Products have autosave drafts, so after a product is renamed (or duplicated as "… (copy)" and renamed) without publishing, new variants still get the old product name. - It is not updated when the product is renamed. The title is only generated when the variant itself is saved, and the products collection has no hook that updates its variants. Renaming a product leaves all its existing variants with the old name until each one is re-saved.
- Edits to the title are silently discarded. The hook overwrites
titleon every save (optionsis required, so it is always set), but the field is editable in the admin panel and its description ("This is populated by default") suggests the generated value is only a default that can be overridden.
Since the title is always derived, it could read the product with draft: true, be regenerated from a products afterChange hook when the product title changes, and be readOnly with a description that says it is generated.
This affects both v3 and v4: the same hook ships in 4.0.0-beta.4 and is on main, and neither has a products hook that updates variant titles.
Link to the code that reproduces this issue
Reproduction Steps
- Clone this repo and open the
variant-title-ignores-draft-and-manual-title/directory pnpm installpnpm test:int: all three tests fail. Each creates a published product "Shirt" with a "Size" variant type and a variant with the option "Small".
× uses the latest draft of the product
Expected: "T-Shirt — Small"
Received: "Shirt — Small"
× updates the variant title when the product is renamed
Expected: "T-Shirt — Small"
Received: "Shirt — Small"
× marks the always-generated title field as read-only
(updating the title to "Edited title" returns "Shirt — Small")
Expected: true
Received: undefined
Which area(s) are affected?
plugin: ecommerce
Environment Info
Relevant Packages:
payload: 3.92.0
@payloadcms/plugin-ecommerce: 3.92.0
@payloadcms/db-sqlite: 3.92.0
Node: 22.23.3, pnpm: 11.5.1, darwin arm64
- Dominant language
- TypeScript
- Stars
- 45.3k
- Forks
- 4.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 299
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from payloadcms/payload
-
WhereBuilder throws "Cannot read properties of undefined (reading 'value')" when the list URL filters on a field that is not filterablePossibly taken A pull request linked to this issue is open or already merged. OpenBug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
payloadcms/payload#19002 · 1 comment ·
Maintainers usually reply within 1 day
-
Regression: `findByID` with `disableErrors: true` throws `NotFound` for null/empty ids since 3.91.0Possibly taken @Krrishkumar125 claimed this 3 days ago. Openarea: core Bug invalid-reproduction status: needs-triage v3
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
payloadcms/payload#18935 · 1 comment ·
Maintainers usually reply within 1 day
-
bug: Local API call with req resets req.fallbackLocale to defaultLocalePossibly taken A pull request linked to this issue is open or already merged. Openarea: core Bug created-by: Contributor
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
payloadcms/payload#18768 ·
Maintainers usually reply within 1 day
-
[plugin-multi-tenant] Infinite redirect loop with custom tenantFieldName and isGlobal collectionsPossibly taken A pull request linked to this issue is open or already merged. OpenBug plugin: multi-tenant status: needs-triage v3
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
payloadcms/payload#18690 ·
Maintainers usually reply within 1 day
-
Global update drops overrideAccess, so Local API updateGlobal fails filterOptions validation (3.90 regression)Possibly taken @PINYOPATTANAWASANPORN claimed this 12 days ago. Openarea: core Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
payloadcms/payload#18674 · 2 comments · 1 reaction ·
Maintainers usually reply within 1 day
All issues in payloadcms/payload
Similar issues
-
bug require-triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
expressjs/expressjs.com#2549 · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
umami-software/umami#4686 · 1 comment ·
Maintainers usually reply within 2 days
-
[Bug]: Device screenshot fails with 500 on iPhone Duo (Xcode 27.2): serve-sim calls simctl without --displayPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
pingdotgg/t3code#24900 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
inu-appcenter/UNIDorm-web#411 ·
Maintainers usually reply within 1 day
-
🐛 bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 2 days