Working with Markets in EPiServer Commerce 7.5

It is a very strong feature of EPiServer Commerce 7.5 being an Enterprise Commerce Platform combined with the power of all CMS features. It can help businesses to grow and target correct markets and earn more profits. The "Market" means that you can define multiple markets, each with its own product catalog, language, currency, and promotions, for a single-site. It can be any type of division of Business, e.g. For a Business there can be more than one markets within the same country, language or a currency or another business may divide its markets at country level. E.g.
A Book Seller Company may be selling different type of books in different parts of countries and they may require two different sites/markets or a car seller company selling cars in different countries
Implementing markets

You can define your own markets by implementing the IMarket interface, and set up a list of supported languages (through CultureInfo), countries in that market, supported currencies, as well as the default language and currency to be used. Through the use of the ICurrentMarket interface, you can easily get the current market throughout the application. The ICurrentMarket interface should be registered at the initialization step of your application, and this can be done by implementing IConfigurableModule. E.g.
public class AustralianMarket: ICurrentMarket
{}

public class MarketConfigs : IConfigurableModule
public void ConfigureContainer(ServiceConfigurationContext context)
{
context.Container.Configure(ce =>
{
ce.For<ICurrentMarket>().Singleton().Use<AustralianMarket>();
});
}

Getting all available markets
// Get all available markets.
ICurrentMarket _currentMarketService = ServiceLocator.Current.GetInstance<ICurrentMarket>();
var marketStorage = _currentMarketService as MarketStorage;
var listMarket = marketStorage.GetAvailableMarkets();

Getting current market
public ICurrentMarket CurrentMarket{
    get{
        if(currentMarket==null)
        {
        var _currentMarketService = ServiceLocator.Current.GetInstance<ICurrentMarket>();
        currentMarket = _currentMarketService.GetCurrentMarket();
        }
        return currentMarket;
    }
}
Setting current market
// Set current markets.
var _currentMarketService = ServiceLocator.Current.GetInstance<ICurrentMarket>();
var marketA = _currentMarketService as AustralianMarket;
marketA.SetCurrentMarket(YourMarketId);

Getting Carts
To implement market dependent carts, you can use the CartHelper constructor with the last one as an instance of IMarket.
CartHelper(string name, Guid userId, IMarket market)

Getting Saleprice
public  Price GetSalePrice(Entry entry, decimal quantity)
{
    return StoreHelper.GetSalePrice(entry, quantity, CurrentMarket);

}

Comments

  1. Great blog Drew! I like the intern idea, what a great resource for new content which can be a challenge at times. Increasing website traffic boils down to fresh,unique content that is optimized and having your content go viral.
    ecommerce

    ReplyDelete
  2. HI, Do you have any examples using IPriceDetailService and IPriceDetailValue?

    ReplyDelete
  3. Securaloan, sorry for late reply, Are you still looking for an example?

    ReplyDelete
  4. I am having difficulty initializing most of these services for some quartz jobs. Any help will be much appreciated.

    ReplyDelete

Post a Comment

Popular posts from this blog

EPiServer CMS 11 Useful SQL Queries - 1

EPiServer CMS 11 Useful SQL Queries - 2

Strongly Type Models in EPiServer Commerce