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

Multi-site

This article describes how to filter for catalogs based on site.

When using multi-site, you can create site-specific catalogs. To filter for catalogs based on site, you can use the following API:

//Using commerce search prvoider,
ServiceLocator.Current.GetInstance<SearchManager>().Search(new CatalogEntrySearchCriteria
{
    CatalogNames = GetCatalogNames(),
});

 

 private StringCollection GetCatalogNames()
{
    var catalogNames = new StringCollection();
    var ids = ServiceLocator.Current.GetInstance<ICatalogSystem>().GetCatalogsBySite(SiteDefinition.Current?.Id ?? Guid.Empty);
    if (ids == null || !ids.Any())
    {
        return catalogNames;
    }
    var catalogs = _catalogSystem.GetCatalogDto().Catalog.Where(x => ids.Contains(x.CatalogId));
    catalogNames.AddRange(catalogs.Select(x => x.Name).ToArray());
    return catalogNames;
}
//Using Find
var query = ServiceLocator.Current.GetInstance<IClient>().Search<EntryContentBase>();
var ids = ServiceLocator.Current.GetInstance<ICatalogSystem>().GetCatalogsBySite(SiteDefinition.Current?.Id ?? Guid.Empty);
if (ids?.Any() ?? false)
{
   query = query.Filter(x => x.CatalogId.In(ids));
}
var result = query.GetContentResult();