[plugin-ecommerce] Inventory defaults to 0, so products that don't track stock (digital goods) can't be bought; no per-product "unlimited" option

Aperta
#19,616 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@TejasLamba2006 ci sta già lavorando.

Dal 18/11/2026.

  • #19715 di @TejasLamba2006 — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
postgresql, typescript
Ambito
backend, database

Direzione di ricerca

Start by tracing inventoryField and defaultProductsValidation, then follow confirmOrder to decrementInventory; the issue also points to #18288 for related inventory configuration behavior. Compare how null inventory is handled with the default value and decrement path, including variants. Done means untracked or unlimited products can be purchased without breaking stock tracking for physical products.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug Payload OSS
Describe the Bug

In a shop that sells both physical and digital products, stock only makes sense for the physical ones. The plugin has no per-product way to say "this product doesn't track stock", and the defaults make digital products fail in two places:

  1. New products start sold out. inventoryField sets defaultValue: 0, and defaultProductsValidation treats inventory === 0 as out of stock. Every new product created in the admin is therefore refused at initiate until someone enters a number or clears the field. Clearing it works because null is treated as unlimited, but nothing in the admin tells editors that.
  2. Stock is decremented for every line. confirmOrder → decrementInventory runs $inc: -quantity for every transaction item, digital ones included. If an editor enters a number such as 100 to get past point 1, the product sells down to 0 and then starts refusing purchases again. With a non-negative check on the column, settlement fails after the customer has already paid.

Turning stock off globally (inventory: false) isn't a workaround for mixed shops: physical products lose stock tracking. Per #18288 the decrement also doesn't read the inventory config, so false may not stop it anyway.

Expected

One of these, or something similar:

  • a per-product (and per-variant) "Track inventory" toggle, with untracked products skipped by both the validation and the decrement, or
  • null (unlimited) as the default, documented as "leave empty for unlimited", with the admin able to show the field conditionally.
Workaround we use

A beforeChange field hook on inventory stores null for non-physical product types; null + -1 stays null in Postgres. We also hide the field for those types with an admin.condition.

Related

#18288 (inventory config not passed to the decrement / fieldName unused)

Environment
  • @payloadcms/plugin-ecommerce 4.0.0-beta.8
  • Postgres adapter
Lingua principale
TypeScript
Stelle
45.8k
Fork
4.4k
Merge medio
3g 4h
PR unite (30g)
210

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di payloadcms/payload

Tutte le issue di payloadcms/payload

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.