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:

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?