Stock Alerts

Sends a shop one email when product or variant inventory crosses a low stock threshold, with backorder handling and a storefront-readable status field.

Community 1 145/wk MIT v1.0.0

Installation

pnpm add payload-stock-alerts

About

This plugin watches product and variant inventory in a Payload ecommerce setup and sends a single email the moment a level crosses downward past a configurable low stock threshold. It is built to sit alongside `@payloadcms/plugin-ecommerce` but works with any collection that exposes an `inventory` field. The notification fires once per crossing, not on every save: a date flag (`lowStockNotifiedAt`) is written when the alert is sent and cleared the first time stock climbs back above the threshold, which arms the next crossing. Because the official ecommerce plugin decrements stock through `payload.db.updateOne` after an order is confirmed, and that call bypasses collection hooks entirely, the plugin also hooks `afterChange` on the orders collection. On order creation it calculates `current level minus quantity ordered` and alerts on that predicted level. A `beforeValidate` hook refuses negative inventory on writes that go through Payload, though it cannot block the official plugin's direct database update, so a sale can still push stock below zero; the plugin reports that state as `out-of-stock`. A read-only virtual `stockStatus` field (`in-stock`, `low-stock`, `out-of-stock`, `backorder`) is added to every product and variant document so a storefront can show backorder state without a second query. Two REST endpoints are exposed under `/api/stock-alerts`: `GET /low-stock` returns the current low stock list read fresh, and `POST /check` scans and notifies for everything below threshold that has not yet been flagged. Both are guarded by an `isAdmin` access check that defaults to looking for the `admin` role. Email is sent through `payload.sendEmail`, so it relies on whatever email adapter the project already has configured; there is no mail library bundled and no runtime dependencies. Per-item overrides are supported through a `lowStockThreshold` number field and an `allowBackorder` checkbox, with store-level defaults filling the gaps.

Package info

Package name
payload-stock-alerts
Latest version
1.0.0
Unpacked size
36 kB
License
MIT
Weekly downloads
145
Last publish
Aug 21, 2026

More from Poseidonas

View profile