Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Create a feed for Episerver Forms, filling a dropdown with order numbers

See this post for the complete instructions for creating a feed for Episerver Forms.

Read my blog here

Powered by ReSharper image

using System.Collections.Generic;
using EPiServer.Forms.Core.Feed.Internal;
using EPiServer.ServiceLocation;
/// <summary>
/// Class CommerceFeedProvider.
/// </summary>
/// <seealso cref="EPiServer.Forms.Core.Feed.Internal.IFeedProvider" />
public class CommerceFeedProvider : IFeedProvider
{
/// <summary>
/// Gets the feeds.
/// </summary>
/// <returns>A list of <see cref="IFeed"/>.</returns>
public IEnumerable<IFeed> GetFeeds()
{
return ServiceLocator.Current.GetAllInstances<IFeed>();
}
}
using System.Collections.Generic;
using System.Linq;
using EPiServer.Commerce.Order;
using EPiServer.Forms.Core;
using EPiServer.Forms.Core.Feed.Internal;
using EPiServer.Forms.EditView.Models.Internal;
using EPiServer.ServiceLocation;
/// <summary>
/// Class CustomerOrdersFeed.
/// </summary>
/// <seealso cref="EPiServer.Forms.Core.Feed.Internal.IFeed" />
/// <seealso cref="EPiServer.Forms.Core.IUIEntityInEditView" />
[ServiceConfiguration(ServiceType = typeof(IFeed))]
public class CustomerOrdersFeed : IFeed, IUIEntityInEditView
{
/// <summary>
/// The order repository
/// </summary>
private readonly IOrderRepository orderRepository;
/// <summary>
/// Initializes a new instance of the <see cref="CustomerOrdersFeed"/> class.
/// </summary>
/// <param name="orderRepository">The order repository.</param>
public CustomerOrdersFeed(IOrderRepository orderRepository)
{
this.orderRepository = orderRepository;
}
/// <summary>
/// Gets a value indicating whether [available in edit view].
/// </summary>
/// <value><c>true</c> if [available in edit view]; otherwise, <c>false</c>.</value>
public bool AvailableInEditView
{
get
{
return true;
}
}
/// <summary>
/// Gets or sets the description.
/// </summary>
/// <value>The description.</value>
public string Description
{
get
{
return "Customer orders";
}
set
{
}
}
/// <summary>
/// Gets the edit view friendly title.
/// </summary>
/// <value>The edit view friendly title.</value>
public string EditViewFriendlyTitle
{
get
{
return "Customer orders";
}
}
/// <summary>
/// Gets the extra configuration.
/// </summary>
/// <value>The extra configuration.</value>
public string ExtraConfiguration { get; }
/// <summary>
/// Gets the identifier.
/// </summary>
/// <value>The identifier.</value>
public string ID
{
get
{
return "a205dbcd-d672-4a50-8c70-0b5ea55121f3";
}
}
/// <summary>
/// Loads the items.
/// </summary>
/// <returns>A list if <see cref="IFeedItem"/>.</returns>
public IEnumerable<IFeedItem> LoadItems()
{
IEnumerable<IPurchaseOrder> orders = this.orderRepository.Load<IPurchaseOrder>();
return orders.Select(order => new FeedItem { Key = order.OrderNumber, Value = order.OrderNumber })
.Cast<IFeedItem>()
.ToList();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.