PreProcessOrder event

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:

  1. Perform any business logic needed before purchasing and cancel an order, if it does not pass validation.
  2. Check inventory quantities with a third party software package such as SAP, NetSuite, QuickBooks and Microsoft Dynamics.
  3. 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.
  4. Check low inventory quantities – send email to applicable purchaser.
  5. 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 EcommerceEvents_PreProcessOrder.

In the method accepts the following arguments:

  • cartOrderId
    Represents the ID of the cart order that is currently being processed.
  • checkoutState
    Represents information about the checkout like shipping and billing addresses, payment method, shipping method, etc.
  • customer
    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:

  • IsOrderValid
    Specifies whether the order is valid. If it is invalid the processing will be interrupted.
  • StatusMessage
    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:

Want to learn more?

Sign up for our free beginner training. Boost your credentials through advanced courses and certification.
Register for Sitefinity training and certification.

Was this article helpful?