This event occurs before the order is processed. At this point you can execute any logic that needs to be done before the order is processed for payment. For example, you can use this event to do the following:
- Perform any business logic needed before purchasing and cancel an order, if it does not pass validation.
- Check inventory quantities with a third party software package such as SAP, NetSuite, QuickBooks and Microsoft Dynamics.
- Allow specific products to be purchased based on rules.
For example, allow product B to be purchased, only if product A has been purchased in the past by that user or role.
- Check low inventory quantities – send email to applicable purchaser.
- If needed, change pricing, based on roles or some other business rules.
In the sample below, you can see how the definition of the handle method must look like. In this sample, the handle method is named
In the method accepts the following arguments:
Represents the ID of the cart order that is currently being processed.
Represents information about the checkout like shipping and billing addresses, payment method, shipping method, etc.
Represents the Customer instance for the user that is currently placing the order.
The handler method must return an instance of the OrderValidator class. You use this class to validate the order by your custom criteria. The class exposes the following specific properties:
Specifies whether the order is valid. If it is invalid the processing will be interrupted.
Gets or sets the status message of the validation. Use this value to provide more information about why the order is invalid.
Use the following code sample to hook up to the PreProcessOrder event: