Custom email notification when OrderStatus changed

Gleb Itenberg asked on November 22, 2018 08:00

I need to create a custom email notification logic when order status in changed. I mean, not only email templates, but also a logic that will change recipients depends on Order fields. But I can't find a way to handle OrderStatus change event.

How can I handle OrderStatus change event? Maybe there are any other ways to achieve such behavior?

Correct Answer

Dragoljub Ilic answered on November 22, 2018 11:04

Hi,

I'm not sure if you are looking for something like this, but in this way you can monitor if status of the order is changed:

protected override void OnInit()
{
    base.OnInit();

    OrderInfo.TYPEINFO.Events.Update.Before += Update_Before;
}

And then handle change with this code:

 private void Update_Before(object sender, ObjectEventArgs e)
    {
        var order = e.Object as OrderInfo;

        if (order != null)
        {
            if (order.AnyItemChanged(nameof(OrderInfo.OrderStatusID)))
            {
                //Status is changed
            }
        }
    }

Any other data about changed status and other order data can be retrieved from Kentico API. Check more in documentation.

Best regards, Dragoljub

0 votesVote for this answer Unmark Correct answer

Recent Answers


Suneel Jhangiani answered on November 26, 2018 00:37

Just a word of warning, the Kentico E-commerce module includes some notifications that get sent out depending on the state of the Order when being saved. If you find this interferes with what you are doing you may need to override the OrderInfoProvider.SetOrderInfo() method or disable the built-in notifications.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.