An Order Fulfillment can have its status changed by either:
API call to FulfillmentOperationEndpoint
Internal usage of FulfillmentOperationService#changeFulfillmentStatus
Asynchronously from a message listener to automatically change status, ex. AbstractAutoStatusChangeListener
Synchronously after another operation is complete, ex. at the end of FulfillmentCapturingPaymentListener
Two types of status change are supported:
Complete status change
Changes the status of the entire fulfillment
Partial status change
Request to update only certain quantities of certain items within the fulfillment
Splits the existing fulfillment
A new Order Fulfillment with the requested items and new status is created and returned
The rest of the items will remain in the existing Order Fulfillment with the old status
In order for an Order Fulfillment to change to a particular status, a FulfillmentStatusChangeHandler must be registered which can update to that status. Generally these handlers define:
A target status - the status they can handle moving Order Fulfillments into
Valid originating statuses - the statuses they can handle moving Order Fulfillments from
For example, there’s a status CAPTURING_PAYMENT which is where payment capture occurs. A business rule dictates that we can only start capturing payment from the NEW status. So there is a CapturingPaymentStatusChangeHandler which implements FulfillmentStatusChangeHandler and can handle a target status of CAPTURING_PAYMENT and an originating status of NEW.
FulfillmentOperationService receives the request to change an Order Fulfillment’s status, FulfillmentStatusChangeRequest
FulfillmentProvider reads the Order Fulfillment by ID through the OrderService
FulfillmentStatusChangeValidator checks that the Order Fulfillment has enough quantity of the items for the requested status change
FulfillmentOperationService searches through the FulfillmentStatusChangeHandlers for one that can handle the request
Each FulfillmentStatusChangeHandler checks if it can move a fulfillment in the existing original status to the new target status
FulfillmentStatusChangeHandler checks if we need to split up the fulfillment
If the request didn’t specify any item quantities, or specified all the items, then we’ll just update the existing fulfillment
Otherwise the FulfillmentSplittingService will split the requested items out of the existing Order Fulfillment into a new Order Fulfillment
FulfillmentStatusChangeHandler updates the new Order Fulfillment to the new status (or if there was no split, updates the existing fulfillment)
FulfillmentProvider saves all relevant fulfillments, split or updated, through the OrderService by replacing or creating them
Most handler implementations will publish a FulfillmentStatusChangeEvent on a specialized topic (see Messaging)
FulfillmentStatusChangeHandler and then FulfillmentOperationService return the fulfillment that had its status changed