How does it work?
Well, first of all E-Commerce Services is configured using "site" settings and "business" settings. Site settings are general settings for your site like: links to item locations, design, defaults, formats etc. Whilst business settings define things like VAT regions, Currencies, Order statusses etc. Business settings can be placed anywhere you like because they are linked under site settings. The site settings itself however are resolved through a pipeline called "getConfiguration"
The getConfiguration pipeline
The configuration pipeline is configured in the Sitecore.Ecommerce.config file and looks like this:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> <sitecore> <getConfiguration> <processor type="Sitecore.Ecommerce.Pipelines.GetConfiguration.GetFromContextSite, Sitecore.Ecommerce.Kernel" /> <processor type="Sitecore.Ecommerce.Pipelines.GetConfiguration.GetFromWebSite, Sitecore.Ecommerce.Kernel" /> <processor type="Sitecore.Ecommerce.Pipelines.GetConfiguration.GetFromLinkManager, Sitecore.Ecommerce.Kernel" /> <processor type="Sitecore.Ecommerce.Pipelines.GetConfiguration.GetFromResolver, Sitecore.Ecommerce.Kernel" /> </getConfiguration> </sitecore> </configuration>
The solution
The solution to the problem is very simple. I created a custom processor that retrieves the Site Settings relative to the ContentStartPath property of the website. Just insert this processor at the first position in the pipeline and you're good to go!
Good luck!
namespace Sitecore.SharedSource.Pipelines.GetConfiguration { class GetFromContextSiteOutsideRoot : GetConfigurationProcessor { private static readonly string SettingsRootTemplateId = Settings.GetSetting("Ecommerce.Settings.SettingsRootTemplateId"); private const string EcommerceSiteSettingsAttribute = "EcommerceSiteSettings"; private const string EcommerceSiteSettingsDefaultValue = "/Home/Site settings"; public GetFromContextSiteOutsideRoot() { } public override void Process(ConfigurationPipelineArgs args) { object obj1 = IoCContainerExtensions.Resolve(Sitecore.Ecommerce.Context.Entity, args.ConfigurationItemType, new ResolverOverride[0]); if (!(obj1 is IEntity) || Sitecore.Context.Site == null || Sitecore.Context.Database == null) return; string part2 = Sitecore.Context.Site.Properties[GetFromContextSiteOutsideRoot.EcommerceSiteSettingsAttribute]; if (string.IsNullOrEmpty(part2)) part2 = GetFromContextSiteOutsideRoot.EcommerceSiteSettingsDefaultValue; Item obj2 = Sitecore.Context.Database.GetItem(FileUtil.MakePath(Sitecore.Context.Site.ContentStartPath, part2)); if (obj2 == null || obj2.Template.ID.ToString() != GetFromContextSiteOutsideRoot.SettingsRootTemplateId && Enumerable.FirstOrDefault<TemplateItem>(Enumerable.Where<TemplateItem>((IEnumerable<TemplateItem>)obj2.Template.BaseTemplates, (Func<TemplateItem, bool>)(x => x.ID.ToString() == GetFromContextSiteOutsideRoot.SettingsRootTemplateId))) == null) return; IEntity entity = (IEntity)obj1; Item source = obj2.Axes.SelectSingleItem(string.Format(".//*[@@name='{0}']", (object)entity.Alias)); this.RegisterInstance(args, (IEntity)obj1, source); args.AbortPipeline(); } } }
Geen opmerkingen:
Een reactie posten