Handling Notifications
Many kinds of notifications are fired by Rescope Commerce. These notifications allow you to take custom actions based on events such as an order being paid or a basket being updated.
Available notifications
See the Rescope.Commerce.Core.Events namespace for notifications.
Creating a notification handler
To listen for notifications, implement the IRescopeNotificationHandler interface.
Here's an example:
public class OrderPaidHandler : IRescopeNotificationHandler<OrderPaidNotification>
{
public async Task Handle(OrderPaidNotification notification)
{
// do something here
}
}
Composing handlers
Once you have created your custom notification handler, use a composer to wire things up:
public class EventComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.WithEvent<OrderPaidNotification>()
.AddHandler<OrderPaidHandler>();
}
}
Removing default handlers
Rescope Commerce registers notification handlers for stock and umbraco member functionality. If you wish to handle this logic yourself, it's possible to remove default handlers before adding your own.
Warning
Although possible, it's not recommended to remove our default handlers as you may interfere with updates or core functionality offered by Rescope Commerce.
// remove DefaultBasketUpdatedHandler, this handler is
// added by Rescope Commerce to deal with umbraco member properties
builder.WithEvent<BasketUpdatedNotification>()
.RemoveHandler<DefaultBasketUpdatedHandler>();
// remove UpdateStockOnPaidHandler, this handler reduces the
// available stock on items after an order is marked as paid
builder.WithEvent<OrderPaidNotification>()
.RemoveHandler<UpdateStockOnPaidHandler>();