Hide menu Last updated: Oct 12 2015

This topic describes the Market concept, which is central to Episerver Commerce. A single site can have multiple markets, each with its own product catalog, language, currency, and promotions.

Classes in this topic are available in the Mediachase.Commerce or Mediachase.Commerce.Markets namespaces.

CurrentMarket interface

Sites that implement multi-market functionality must also implement the ICurrentMarket interface. The ICurrentMarket implementation must return the market of the current request, and is called to get the appropriate market for the execution of most market-sensitive business logic. You register custom ICurrentMarket implementations at the application's initialization step by implementing IConfigurableModule.

A business's market segmentation strategy determines its implementation of the ICurrentMarket interface. If your business segments markets geographically, you may want to use a prestitial page, an IP geolocation service, or a simple drop-down control to determine a user's region and market.

Markets are not constrained to a region; a business-to-business is likely to permit only authenticated users to use the system, and may assign a market to each customer when the customer is created. In this case, the ICurrentMarket implementation's retrieval of the current market is based on the current authenticated user.

The default, supplied implementation of ICurrentMarket always returns the default market. This is the correct behavior for sites that do not implement multi-market functionality.

The ICurrentMarket interface:

C#
public interface ICurrentMarket
{
    // Gets the current market.
    IMarket GetCurrentMarket();
}

Example: Registering a custom ICurrentMarket implementation:

C#
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.Framework.ServiceLocation;
using Mediachase.Commerce;

// The custom implementation of ICurrentMarket
public class MyCurrentMarketImplementation : ICurrentMarket
{
    public IMarket GetCurrentMarket()
    {
        ... implementation ...
    }
}

[ModuleDependency(typeof(Mediachase.Commerce.Initialization.CommerceInitialization))]
[InitializableModule]
public class MyCurrentMarketModule : IConfigurableModule
{
    public void ConfigureContainer(ServiceConfigurationContext context)
    {
        context.Container.Configure(ce =>
        {
            ce.For<ICurrentMarket>().Singleton().Use<MyCurrentMarketImplementation>();                
        });
    }

    public void Initialize(InitializationEngine context) { }
    public void Preload(string[] parameters) { }
    public void Uninitialize(InitializationEngine context) { }
}

Market definition

A market is represented by an instance of the IMarket interface. The data associated with each market is typically used as a set of guidelines for regional markets. However, the market system is not specifically tied to a region; and languages and currencies are not automatically filtered based on the value of the current market. You can use the MarketImpl class as a default implementation of the IMarket interface.

There always is a default market, with ID MarketId.Default. You can disable this market for sites that implement multi-market functionality, but do not delete it.

The IMarket interface:

C#
public interface IMarket
{
    // Gets the market's unique identifier.
    MarketId MarketId { get; }

    // Gets a value indicating if the the market is enabled.
    bool IsEnabled { get; }

    // Gets the market's name.
    string MarketName { get; }

    // Gets the default language for the market.
    CultureInfo DefaultLanguage { get; }

    // Gets the available languages for the market.
    IEnumerable<CultureInfo> Languages { get; }

    // Gets the default currency for the market.
    Currency DefaultCurrency { get; }

    // Gets the available currencies for the market.
    IEnumerable<Currency> Currencies { get; }

    // Gets the countries associated with the market.
    IEnumerable<string> Countries { get; }
}

Interacting with markets

Access market data with the IMarketService API, which exposes simple create/replace/update/delete operations for market data.

The IMarketService interface:

C#
public interface IMarketService
{
    // Gets all markets in the system.
    IEnumerable<IMarket> GetAllMarkets();

    // Get a single market by ID, or null if the market ID is not found.
    IMarket GetMarket(MarketId marketId);

    // Adds a new market to the market system.
    void CreateMarket(IMarket market);

    // Updates an existing market in the market system.
    void UpdateMarket(IMarket market);

    // Deletes a market by ID.
    void DeleteMarket(MarketId marketId);
}

Markets, orders, carts, and wishlists

To enable processing when the ICurrentMarket implementation may not be available, orders, carts, and wishlists include a market ID.

Carts are market-dependent, so are unique to a user and market, instead of just the user. If a site lets a user switch markets, then switching the market may also switch associated carts to a new or different carts. Because wishlists are carts, this also applies to wishlists.

Comments