Documentation

Ucommerce includes full API reference documentation and lots of helpful articles to help you build your e-commerce site as effortlessly as possible.

Topics Payment Providers
v7.18

Dashboard Feed

In this article, we will dive into how the feed works, and how to deliver items to Ucommerce Dashboard. You will also learn how you can leverage this to generate your own feed messages for the Digital Merchant.

In-memory Feed

The Feed concept is centered around a Ucommerce.Dashboard.IFeedService, which is responsible for delivering the feed. Besides that it also has the responsibility for adding new messages to the feed.

Our implementation of the interface is the Ucommerce.Dashboard.Impl.InMemoryFeed, which is holding an in-memory fixed size (LIFO) list of items. You can change the size of the list by adding below component to custom.config with the desired size as the FeedSize value.

    
        <component
          id="FeedService"
          service="UCommerce.Dashboard.IFeedService, UCommerce"
          type="UCommerce.Dashboard.Impl.InMemoryFeed, UCommerce">
          <parameters>
            <FeedSize>20</FeedSize>
          </parameters>
        </component>
    

Feed Item Types

Besides the framework, Ucommerce comes with some feed item types out of the box as well. That shows some of the important activities that are happening in the store right now.

  • Campaign triggered
    • Show the Digital Merchant that a campaign was used for a new order.
  • Order was placed
  • New Customer
    • Show that the Digital Merchant has a new customer.
  • Recurring Customer
    • Show the Digital Merchant that a customer came back for consecutive orders.
  • Customer is checking out
    • This is triggered when the billing information has been provided and gives the Digital Merchant the ability to call the customer and help complete the rest of the checkout.

Custom Feed Item Types

You can of cause create your own feed items and deliver them to the IFeedService, in this section we will go through the needed steps to make this happen.

We will use the "Order was placed" type as our example.

Case: 'When an order is placed we want to add a new feed item to the dashboard'

  • Identifying the place to hook into Ucommerce. Since we wont to add the feed when an order is placed, the Checkout pipeline is a good candidate for this.
  • Extending the checkout pipeline with a new task that will be executed when the basket has been converted to an order.
  • Creating the pipeline task. We will add the new item to the IFeedService where we add a Text and the Type of feed we are adding. (The type is just a string, used in the client for presentation.)
    
        public class FeedOrderPlacedTask : IPipelineTask<PurchaseOrder>
        {
            private readonly IFeedService _feedService;
    
            public FeedOrderPlacedTask(IFeedService feedService)
            {
                _feedService = feedService;
            }
    
            public PipelineExecutionResult Execute(PurchaseOrder subject)
            {
                _feedService.AddFeedItem(new FeedItem()
                {
                    Text = $"Order {subject.OrderNumber} was placed for {new Money(subject.OrderTotal.GetValueOrDefault(), subject.BillingCurrency).ToString()}", 
                    Type = Constants.Feed.OrderPlaced,
                });
    
                return PipelineExecutionResult.Success;
            }
        }
    
  • Then we want to give the Digital Merchant the ability to quickly access the order. This can be done by adding a value to the Url field on the Feed. In this case, we are using the IPathService which resolves the path down to Ucommerce for the current CMS.
    
        public class FeedOrderPlacedTask : IPipelineTask<PurchaseOrder>
        {
            private readonly IFeedService _feedService;
            private readonly IPathService _pathService;
    
            public FeedOrderPlacedTask(IFeedService feedService, IPathService pathService)
            {
                _feedService = feedService;
                _pathService = pathService;
            }
    
            public PipelineExecutionResult Execute(PurchaseOrder subject)
            {
                var orderUrl = $"{_pathService.GetPath()}orders/EditOrder.aspx?id={subject.OrderId}";
    
                _feedService.AddFeedItem(new FeedItem()
                {
                    Text = $"Order {subject.OrderNumber} was placed for {new Money(subject.OrderTotal.GetValueOrDefault(), subject.BillingCurrency).ToString()}", 
                    Type = Constants.Feed.OrderPlaced,
                    Url = orderUrl, 
                });
    
                return PipelineExecutionResult.Success;
            }
        }
    
  • Finally we need to make sure that when we are presenting this feed item to the Digital Merchant and that he is allowed to see it. In this case, if he is allowed to see the order placed for the store. We use the role service to get the purchaseOrderRole for the current store and persist that down to the RoleId on the FeedItem. The InMemoryFeed will than make sure to remove items that the Digital Merchant does not have permission to.
    
        public class FeedOrderPlacedTask : IPipelineTask<PurchaseOrder>
        {
            private readonly IFeedService _feedService;
            private readonly IRepository<Role> _roleRepository;
            private readonly IPathService _pathService;
    
            public FeedOrderPlacedTask(IFeedService feedService, IRepository<Role> roleRepository, IPathService pathService)
            {
                _feedService = feedService;
                _roleRepository = roleRepository;
                _pathService = pathService;
            }
    
            public PipelineExecutionResult Execute(PurchaseOrder subject)
            {
                var purchaseOrderRole = _roleRepository
                    .Select(x => x.RoleType == 30)
                    .ToList()
                    .OfType<PurchaseOrderRole>()
                    .FirstOrDefault(x => x.Allows(subject));
    
                var orderUrl = $"{_pathService.GetPath()}orders/EditOrder.aspx?id={subject.OrderId}";
    
                _feedService.AddFeedItem(new FeedItem()
                {
                    Text = $"Order {subject.OrderNumber} was placed for {new Money(subject.OrderTotal.GetValueOrDefault(), subject.BillingCurrency).ToString()}", 
                    Type = Constants.Feed.OrderPlaced,
                    Url = orderUrl, 
                    RoleId = purchaseOrderRole.RoleId
                });
    
                return PipelineExecutionResult.Success;
            }
        }
    

After this task has been added to the IOC it is ready to be used.