I had the same issue and was not able to resolve this with OOTB functionality. You could change the source
field (query:$home
) of the OOTB Search Box Template (/sitecore/templates/Feature/Experience Accelerator/Search/Rendering Parameters/Search Box/SearchCriteria/SearchResultPage
) but this is not a recommended approach.
Therefore, I created my own rendering and inherited from the SearchBoxRepository
class. By overriding the GetSearchResultPageUrl()
method I was able to get my site specific Search Results Page while the rendering was placed in the header (in a partial design in the shared site).
1. Create a feature project in your solution which contains a controller
and a repository
.
public class MultiSiteSearchBoxController : StandardController
{
private readonly IMultiSiteSearchBoxRepository _repository;
public MultiSiteSearchBoxController(IMultiSiteSearchBoxRepository repository)
{
_repository = repository;
}
protected override object GetModel()
{
return _repository.GetModel();
}
}
public interface IMultiSiteSearchBoxRepository : IModelRepository
{
}
[Service(typeof(IMultiSiteSearchBoxRepository), Lifetime = Lifetime.Transient)]
public class MultiSiteSearchBoxRepository : SearchBoxRepository, IMultiSiteSearchBoxRepository
{
public MultiSiteSearchBoxRepository(ISiteInfoResolver siteInfoResolver, IVariantsRepository variantsRepository, IScopeService scopeService)
:base(siteInfoResolver, variantsRepository, scopeService)
{
}
public override IRenderingModelBase GetModel()
{
SearchBoxRenderingModel model = (SearchBoxRenderingModel)base.GetModel();
return model;
}
protected override string GetSearchResultPageUrl()
{
// get your settings item based on the current context (country site 1 or country site 2)
var multiSiteSearchBoxSettings = dosomething_to_get_your_country_site_searchbox_settings();
if (multiSiteSearchBoxSettings == null)
{
return base.GetSearchResultPageUrl();
}
// now lets get the page you have set inside your country site 1 or country site 2 settings item
var searchResultsPagePath = LinkManager.GetItemUrl(Sitecore.Context.Database.GetItem(multiSiteSearchBoxSettings[The_ID_Of_Your_SearchResultsPage_Field]));
return string.IsNullOrEmpty(searchResultsPagePath) ? base.GetSearchResultPageUrl() : searchResultsPagePath;
}
}
2. Create the rendering
Basically, it's a clone of the OOTB Search Box rendering (/sitecore/layout/Renderings/Feature/Experience Accelerator/Search/Search Box
) except it's linked to our own controller.
3. Create the settings template which holds the link to your site specific Search Results Page
4. Add settings item (based on the latter template) to each Country site
4. Finally, add the Multi Site Search Box rendering to your partial design in the Shared site
Just leave the Search Result Page
field blank since we will get our own url by overriding the GetSearchResultPageUrl()
method.