Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Loading...
Applies to versions: 10 and higher
Other versions:
ARCHIVED This content is retired and no longer maintained. See the version selector for other versions of this topic.

Markets

Recommended reading 
Note: This documentation is for the preview version of the upcoming release of CMS 12/Commerce 14/Search & Navigation 14. Features included here might not be complete, and might be changed before becoming available in the public release. This documentation is provided for evaluation purposes only.

This topic describes the Market concept, which is central to Optimizely 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.

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

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.

[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>();
  }
}

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; }
  }

Interacting 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 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 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 wishlists are carts, this also applies to wishlists.

Do you find this information helpful? Please log in to provide feedback.

Last updated: Jul 02, 2021

Recommended reading