OrderIsPaid Change
This article describes the best approach for detecting OrderIsPaid Change.
If you had ever faced a requirement to detect changes of the OrderIsPaid column, you have most likely found that using Custom Global Event Handlers for this is less than optimal. This is because the event is fired on every Order change, and not just the OrderIsPaid change. The solution is to add an additional OrderIsPaid status for tracking and comparison of this column.
The best approach to this problem is to avoid Event Handlers altogether, by using a Custom Provider that overrides the default ProcessOrderIsPaidChangeInternal method. An example provider could look like this:
using System;
using System.Data;
using CMS.CMSHelper;
using CMS.EcommerceProvider;
using CMS.GlobalHelper;
using CMS.SettingsProvider;
using CMS.SiteProvider;
using System.Linq;
using System.Collections.Generic;
using CustomProviders;
using CMS.Ecommerce;
namespace CustomProviders
{
/// <summary>
/// Customized CustomOrderInfoProvider.cs provider.
/// </summary>
public class CustomOrderInfoProvider : OrderInfoProvider
{
/// <summary>
/// Process order items of given order according to order is paid change.
/// </summary>
/// <param name="oi">Order</param>
protected override void ProcessOrderIsPaidChangeInternal(OrderInfo oi)
{
// If order is paid
if (oi.OrderIsPaid)
{
// Order has been paid, your code here
}
else
{
// Order has been moved from paid back to not paid.
}
base.ProcessOrderIsPaidChangeInternal(oi);
}
}
}
Since this code calls the base method at the end, the default functionality is not interrupted.
Please note that you will also need to create a custom provider loader, as described in the article linked bellow. You can find example implementation of the above Custom Provider, as well as Custom Provider Loader in the
article attachments.
-jd-
See also: Custom Providers
Applies to: Kentico CMS 7