PRODUCT_VARIANT_STOCK_UPDATED is not triggered when order flows change stock
What are you trying to achieve?
Track stock changes of product variants through webhooks.
PRODUCT_VARIANT_STOCK_UPDATED (added in #11630) is currently only triggered by the explicit stock-edit mutations (productVariantStocksUpdate, stockBulkUpdate). None of the order flows trigger it:
- Checkout completion (
allocate_stocks) changesStock.quantity_allocated— no event (onlyPRODUCT_VARIANT_OUT_OF_STOCKwhen availability hits 0). - Fulfillment (
decrease_stock) decrements the physicalStock.quantity— still noPRODUCT_VARIANT_STOCK_UPDATED, only the zero-crossing events. - Order/fulfillment cancellation (
deallocate_stock,deallocate_stock_for_orders,increase_stockrestock) — same.
So an app subscribed to PRODUCT_VARIANT_STOCK_UPDATED sees manual dashboard stock edits, but is blind to the most common source of stock changes: orders. The subscription payload already exposes Stock.quantity and Stock.quantityAllocated, so the event name/payload suggest broader semantics than the current triggers deliver.
Proposed solution
Trigger PRODUCT_VARIANT_STOCK_UPDATED from the warehouse management functions whenever Stock rows are actually modified:
allocate_stocks(checkout completion)decrease_stock(fulfillment — one event per stock with final state, no double-fire from its internal deallocation)increase_stock(restock on fulfillment cancellation)deallocate_stock/deallocate_stock_for_orders(order cancellation)
I have a PR ready implementing this in two commits (physical quantity changes / allocation changes) so the allocation part can be discussed or dropped independently.
Steps to reproduce the problem
- Create a webhook subscribed to
PRODUCT_VARIANT_STOCK_UPDATED - Complete a checkout, fulfill the order (variant with
trackInventory: true) - No webhook delivery happens, although
quantityAllocatedand thenquantitychanged
What did you expect to happen?
PRODUCT_VARIANT_STOCK_UPDATED delivered when order flows change stock.
What are your environment parameters?
Saleor main (3.24.0-a.0)
Source: saleor/saleor