HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Markets

Describes the Market concept in Optimizely Customized 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.

Customized Commerce 14
You register custom ICurrentMarket implementations in ConfigureServices method of the Startup class.

Customized Commerce 10-13

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.

Customized Commerce 14 and higher The ICurrentMarket interface.

public interface ICurrentMarket
      {
        // Gets the current market.
        IMarket GetCurrentMarket();
    
        // Sets the current market.
        void SetCurrentMarket(MarketId marketId);
      }

    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 ...
          }
    
        public void SetCurrentMarket(MarketId marketId)
          {
            ... implementation ...
          }
      }
    
    
    public class Startup
    {
      public void ConfigureServices(IServiceCollection services)
      {
        services.AddSingleton<ICurrentMarket, MyCurrentMarketImplementation>();
      }
    }

Customized Commerce Version 10-13

public interface ICurrentMarket
      {
        // Gets the current market.
        IMarket GetCurrentMarket();
    
        // Sets the current market.
        void SetCurrentMarket(MarketId marketId);
      }
    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 ...
          }
    
        public void SetCurrentMarket(MarketId marketId)
          {
            ... 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.

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 market's description.
        string MarketDescription { 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; }
    
        // Gets the value indicating if the price of the market includes tax or not.
        bool PricesIncludeTax { get; }
      }

Interact with markets

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

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 wish lists

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

Carts are market-dependent, so are unique to a user and market, instead of just a 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 wish lists are carts, this also applies to wish lists.