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 doesn’t 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. Change pricing if needed based on roles or some other business rules.

The handler method for this event, must have the following definition:

private OrderValidator EcommerceEvents_PreProcessOrder(Guid cartOrderId, CheckoutState checkoutState, Customer customer)
{
}

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.

Here is a code example of hooking up to the PreProcessOrder event:

public class Global : System.Web.HttpApplication
{
    protected void Application_Start(object sender, EventArgs e)
    {
        Bootstrapper.Initialized += new EventHandler<Telerik.Sitefinity.Data.ExecutedEventArgs>(Bootstrapper_Initialized);
    }
 
    private void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
    {
        if (e.CommandName == "Bootstrapped")
        {
            EcommerceEvents.PreProcessOrder += new EcommerceEvents.OnPreProcessOrder(EcommerceEvents_PreProcessOrder);
        }
    }
 
    private OrderValidator EcommerceEvents_PreProcessOrder(Guid cartOrderId, CheckoutState checkoutState, Customer customer)
    {
        OrderValidator validator = new OrderValidator();
        validator.IsOrderValid = true;
        validator.StatusMessage = "Order is valid";
 
        return validator;
    }
}

Next steps

+1-888-365-2779
sales@sitefinity.com

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK