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
In @payloadcms/plugin-ecommerce, the payment-initiation endpoint never validates variants. The variant block (if (item.variant) { … }) is nested inside if (item.product && !item.variant) { … }, so it is unreachable:
As a result, for cart items with a variant neither the price check nor the inventory check (defaultProductsValidation / a custom productsValidation) runs. A cart with quantity 2 of a variant that has inventory 1 passes /api/payments/{provider}/initiate. The later decrement in confirmOrder is an unconditional $inc, so stock can go negative.
Still present on main. Fix: move the variant block out of the product-only branch (validate the variant when item.variant is set, otherwise the product).
Ecommerce template (variants enabled). Create a product with a variant; set the variant inventory to 1.
Add that variant to the cart with quantity 2.
POST /api/payments/stripe/initiate (any adapter).
Expected: 400 (out of stock), as happens for products without variants.
Actual: validation is skipped and the adapter's initiatePayment is called; confirm-order then decrements inventory to -1.
Activity
fix(plugin-ecommerce): unnest variant validation during payment initi…
fix: address six more Payload v4 database and ecommerce issues [skip ci]