Custom Pricing Providers in Episerver Commerce

Matthew Mols
3 min readNov 30, 2015

--

Pricing in Episerver Commerce uses a number of factors to determine which price to return when it displays a price to a customer or uses a price to calculate the total for an order. I like to simplify these to the “Who”, “What”, “Where”, and “When” of pricing in Episerver.

These factors are represented in the fields on each price that Episerver allows us to input and that it stores in the Commerce database. We either manage our prices directly in Episerver, or we import them from an external system (PIM, ERP, Order System).

External import is the most common integration method in my experience, and in general, this data format works fairly well for most integration cases as other systems typically use a similar format for storing pricing information.

However, some requirements might require that you step outside the default logic of Episerver. You can accomplish this as a developer by implementing your own pricing providers. These providers are more simply described as implementations of two interfaces: IPriceService and IPriceDetailService

If you want to change how Episerver decides which price is valid, create a custom IPriceService. If you want to change where Episerver stores price data, create a custom IPriceDetailService. In most cases, you will be implementing both of these based upon your requirements.

Once you have your custom implementations, simply inject them at startup in your project via StructureMap. This will tell Episerver to use them internally.

context.Container.Configure(c =>
{
c.For<IPriceService>().Use<MyPriceService>();
c.For<IPriceDetailService>().Use<InMemoryPriceDetailService>();
});

By integrating pricing this way, all the features you expect from Episerver will continue to work. The Catalog UI, Order Workflows, and Promotions will all use your custom providers.

I created some sample pricing providers for my Lab session at Ascend — I’ve put these up on Github in a fork of the Quicksilver reference architecture so you can easily run them on your own. You can find the repo here:

InMemoryPriceDetailService is an in memory data store that demonstrates the ability to store pricing in an external data store. In this case, I used a Dictionary maintained in memory that is seeded at startup.

MyPriceService introduces custom pricing logic which uses a new Price Type called “Price Override”. This Price Type is returned proactively over other prices, even if it isn’t the lowest price available at the time.

These providers aren’t production ready, but they should get you started if you need to integrate with an external system that stores pricing already, or you need to implement custom pricing logic in your own projects.

For more details on Pricing in Episerver, this article in the technical documentation is very thorough and should get you into the details quickly.

--

--

Matthew Mols

I’m a software developer who works mostly in .NET. Currently, I work at @thisisnansen building Episerver CMS & Commerce sites.