Move an order to another warehouse
Trigger. PUT /v1/commerce/orders/:id with a different warehouseId.
Outbox. order.location.changed inside the update transaction. Payload includes the new warehouse id.
Listener. OrderFulfillmentListener.handleOrderLocationChanged, wrapped by IdempotentEventHandlerService as consumer fulfillment.order-location-changed.v1.
Observed rules
- If the order row’s
warehouseIdis no longer the event’snewWarehouseId, the listener returns. A later update won. - Every fulfillment order that is not already
CANCELLEDis set toCANCELLED, and its reservations are released. - Reservations held on the order itself are released. The comment says stock pinned to bins cannot follow the order.
- For
CONFIRMED,FULFILLED, orDELIVERED, the listener callscreateFromOrder. - For earlier statuses it calls
applyCreatedOrder. Theitemsarray on that call is empty.applyCreatedOrderdoes not use that array. It loadsOrderItemrows for the order. Reservation runs only when the order is stillPENDINGandallocatesOwnedStockis true. A confirmed order takes thecreateFromOrderbranch above instead. Details are on What an order status does to fulfillment.
The idempotent handler records ProcessedEvent. A retry of the same outbox event should not cancel and recreate again. A new location change is a new outbox event.