Price agents

This article shows how to create new price agent files or add additional information to price agent price lists.

Details on configuring the price agents are found in the getting started section. The default implementation of price agents does not specify information that is project specific. The following example shows how to modify the price agent price list generation, so that this information can be added.

Create price agent item factory

  1. Create a class library project in Visual Studio and add Litium.Web.Abstractions NuGet package.
  2. Create a class and implement the class Litium.Web.Products.PriceAgents.IPriceAgentItemFactory.

Extend default price agent item factory

  1. Create a class library project in Visual Studio and add Litium.Web.Application NuGet package.
  2. Create a class and add the class Litium.Web.Products.PriceAgents.PriceAgentItemFactory as base class, override needed methods.


The following example adds Manufacturer (by some price agents called "brand") and DeliveryCost (DeliveryPrice) to the price list generated.

using Litium.Web.Products.PriceAgents;
using Litium.Products.PriceCalculator;

namespace Litium.Samples.PriceAgent
    /// <summary>
    /// Adds additional information to the price agent generated price list.
    /// </summary>
    public class SamplePriceAgentItemFactory : PriceAgentItemFactory
        public SamplePriceAgentItemFactory(...) : base(...) { }

        /// <summary>
        /// Create price agent item.
        /// </summary>
        /// <param name="priceAgentItemArgs">Price agent arguments.</param>
        /// <param name="securityToken">Security token</param>
        /// <returns></returns>
        public override PriceAgentItemResult Create(PriceAgentItemArgs priceAgentItemArgs)
            //Let the base class implementation add the default implementation.
            var result = base.Create(priceAgentItemArgs, securityToken);

            var article = priceAgentItemArgs.Article;
            //TODO: read the articles manufacturer custom property setup by the project.
            //To add the manufacturer property to your articles see information under Field templates, fields and property values article.
            //add your own information.
            var manufacturerName = "sample manufacturer";
            result.Manufacturer = manufacturerName;

            //TODO: take the delivery cost value from the delivery method.
            decimal deliveryCost = 100;
            result.DeliveryPrice = deliveryCost.ToString();
            return result;


Adding a new price agent

Litium has built-in implementations for Kelko Prisjakt and Pricerunner price agents. If you wish to add support for another price agent, you need to implement the IPriceAgent interface and mark the class using the Plugin attribute.

The following example creates a dummy price agent, named MyPriceTxt.

  1. Create a class library project in Visual Studio and Litium.Web.Abstractions NuGet package.
  2. Create a class and implement the interface Litium.Web.Products.PriceAgents.IPriceAgent
  3. The class is decorated with the Plugin attribute, in this example it reads as  [Plugin("MyPriceTxt")]
using System.Collections.Generic;
using System.IO;
using System.Text;
using Litium.Owin.InversionOfControl;
using Litium.Web.Products.PriceAgents;

namespace Litium.Samples.PriceAgent
    /// <summary>
    /// This is a fictitious price agent that generate a semicolan seperated price list.
    /// </summary>
    public class MyPriceTxt:IPriceAgent
        /// <summary>
        /// Gets the type of the content.
        /// </summary>
        /// <value>
        /// The type of the content.
        /// </value>
        public string ContentType
            get { return "text/plain"; }

        /// <summary>
        /// Render price agent
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="priceAgentItemResults">The price agent item results.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        public void Render(TextWriter writer, IEnumerable<PriceAgentItemResult> priceAgentItemResults)
            StringBuilder sb = new StringBuilder();

            //DO NOT fetch the product name, or price or any other article information here,
            //instead specify them in the PriceAgentItemFactory implementation.
            foreach (var priceAgentItemResult in priceAgentItemResults)
                string stockBalance = (priceAgentItemResult.StockBalance > 0) ? "1" : "6";

After compiling copy the dll to the wwwroot\bin folder.

To test the results, browse to http://your-domain-name/PriceAgent.axd/MyPriceTxt (if you are using a developer machine, make sure that your domain name and the domain name specified for the website in the Web Publishing module (in the settings in backoffice) are the same.

These are the default implementations for price agents: 

  • KelkoTxt - http://your-domain-name/PriceAgent.axd/KelkoTxt
  • KelkoCsv - http://your-domain-name/PriceAgent.axd/KelkoCsv
  • KelkoTxt - http://your-domain-name/PriceAgent.axd/KelkoTxt
  • KelkoXml - http://your-domain-name/PriceAgent.axd/KelkoXml
  • PriceRunner - http://your-domain-name/PriceAgent.axd/PriceRunner
  • Prisjakt - http://your-domain-name/PriceAgent.axd/Prisjakt

The price agent items are cached and updated regarding to the interval that IPriceAgentItemFactory will return, default set to 1 hour. If you need to update the items faster for example if you have the wrong prices in your file, you can flush the cache for price agents. Add the querystring parameter Refresh=True to the querystring; example: http://your-domain-name/PriceAgent.axd/MyPriceTxt?Refresh=True

Is this page helpful?
Thank you for your feedback!