Vendure stock monitoring plugin
npm install @pinelab/vendure-plugin-stock-monitoringVendure stock monitoring plugin
Section titled “Vendure stock monitoring plugin”This plugin helps you monitor the stock levels in two ways:
- A dashboard widget that displays variants that have stock level’s below their threshold
- An event is emitted when a variant’s stock level drops below a given threshold after each placed order.
Getting started
Section titled “Getting started”- Add the plugin to your
vendure-config.tsto expose aproductVariantsWithLowStockquery in the admin API.
import { StockMonitoringPlugin } from '@pinelab/vendure-plugin-stock-monitoring';
plugins: [ StockMonitoringPlugin.init({ globalThreshold: 10, uiTab: 'My Admin UI Tab', }),];The “Low stock” widget is provided as a React Dashboard extension — no Admin UI compilation step is needed.
When you start the server and login, you can find Low stock under the dashboard’s add widget button. The widget is only shown to administrators with the ReadCatalog permission.
Caveats
Section titled “Caveats”- This plugin doesn’t use the
StockLocationStrategybecause of performance reasons. Instead, it fetches the stock level for each variant from the database and calculates its absolute stock based on thestockOnHandandstockAllocatedfields. - Performance: Each allocation or stock-lowering adjustment in
StockMovementEventcreates a job that triggers a stock check: get saleable stock, compare with variant threshold, and emit event if variant dropped below threshold. Sales (fulfillments) don’t trigger a check, because they lowerstockOnHandandstockAllocatedby the same amount, so saleable stock doesn’t change. - Variants that don’t track inventory (
trackInventoryset toFALSE, orINHERITwhile the global setting is off) never emit the event and aren’t listed in the Low stock widget.
