I am developing a Language Switch for Sitecore-uCommerce solution and using the default uCommerce Item Resolver and UrlService to get nice URLs. So I have the URLs like http://sitename/catalogname/productname/c-XX/p-YY.
Then for every sitecore 'page' item I use LinkManager.GetItemUrl(Context.Item, options) with LanguageEmbedding.Always option.
Now, if my Context.Item is a uCommerce item, then my URL is http://sitename/nl/sitecore/ucommerce/products/3/34/productname/, which will not be caught by uCommerce Item Resolver and I will have the document not found error.
So what I need is to check before if Context.Item is uCommerce item and use URLService instead of LinkManager.
Question: Is there in uCommerce a class like TemplateIDs similar to Sitecore.TemplateIDs? This way I could check if my item derives from base ucommerce product template.
Related question: How can I embed language in uCommerce nice URLs?
Here is HttpRequestBegin pipeline
<httpRequestBegin>
<processor type="Sitecore.Pipelines.PreprocessRequest.CheckIgnoreFlag, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.HttpRequest.EnsureServerUrl, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.HttpRequest.StartMeasurements, Sitecore.Kernel"/>
<processor type="Sitecore.Analytics.Pipelines.HttpRequest.StartDiagnostics,Sitecore.Analytics" patch:source="Sitecore.Analytics.config"/>
<processor type="Sitecore.Pipelines.HttpRequest.IgnoreList, Sitecore.Kernel"/>
<!--
Ensure registered bundles are ignored by http request pipeline
-->
<processor type="Sitecore.FXM.Pipelines.HttpRequest.IgnoreBundleEntries, Sitecore.FXM" patch:source="Sitecore.FXM.Bundle.config"/>
<!-- Register bundles on their first request -->
<processor type="Sitecore.FXM.Pipelines.HttpRequest.OnRequestBundleRegistrarProcessor, Sitecore.FXM" patch:source="Sitecore.FXM.Bundle.config">
<bundles hint="list:AddBundle">
<!--
The FXM client javascript bundle - see registration pipeline below. It requires the current Sitecore instance host name
when creating the bundle, so must be generated as part of a Sitecore request.
-->
<bundle>beacon</bundle>
</bundles>
</processor>
<processor type="Sitecore.Mvc.Pipelines.HttpRequest.DisplayFatalErrors, Sitecore.Mvc" patch:source="Sitecore.Mvc.config"/>
<processor type="Sitecore.Pipelines.HttpRequest.SiteResolver, Sitecore.Kernel"/>
<processor type="Sitecore.ItemWebApi.Pipelines.HttpRequest.SetRuntimeSettings, Sitecore.ItemWebApi" patch:source="Sitecore.ItemWebApi.config"/>
<processor type="Sitecore.ItemWebApi.Pipelines.HttpRequest.CheckMode, Sitecore.ItemWebApi" patch:source="Sitecore.ItemWebApi.config"/>
<processor type="Sitecore.Pipelines.HttpRequest.UserResolver, Sitecore.Kernel"/>
<processor type="Sitecore.ItemWebApi.Pipelines.HttpRequest.ResolveUserFromRequest, Sitecore.ItemWebApi" patch:source="Sitecore.ItemWebApi.config"/>
<processor type="Sitecore.ExperienceExplorer.Business.Pipelines.HttpRequest.EnableExperienceModePipeline, Sitecore.ExperienceExplorer.Business" patch:source="Sitecore.ExperienceExplorer.config"/>
<processor type="Sitecore.Pipelines.HttpRequest.DatabaseResolver, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.HttpRequest.BeginDiagnostics, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.HttpRequest.DeviceResolver, Sitecore.Kernel"/>
<processor type="Sitecore.ExperienceExplorer.Business.Pipelines.HttpRequest.PresetResolverPipeline, Sitecore.ExperienceExplorer.Business" patch:source="Sitecore.ExperienceExplorer.config"/>
<processor type="Sitecore.ExperienceExplorer.Business.Pipelines.HttpRequest.DevicePipeline, Sitecore.ExperienceExplorer.Business" patch:source="Sitecore.ExperienceExplorer.config"/>
<processor type="Sitecore.Pipelines.HttpRequest.LanguageResolver, Sitecore.Kernel"/>
<processor type="Sitecore.ItemWebApi.Pipelines.HttpRequest.ResolveLanguage, Sitecore.ItemWebApi" patch:source="Sitecore.ItemWebApi.config"/>
<processor type="Sitecore.Pipelines.HttpRequest.CustomHandlers, Sitecore.Kernel"/>
<processor type="UCommerce.Sitecore.Pipelines.SetCurrentThreadCultureToCurrentLanguage, UCommerce.Sitecore" patch:source="Sitecore.uCommerce.Pipelines.HttpRequestBegin.config"/>
<processor type="UCommerce.Sitecore.Pipelines.BreakHttpProcessor, UCommerce.Sitecore">
<breakMatches hint="raw:AddBreakOnThisPattern" patch:source="Sitecore.uCommerce.Pipelines.HttpRequestBegin.config">
<breakMatch text="/ucommerceapi"/>
<breakMatch text="/paymentprocessor"/>
<breakMatch text="/paymentrequest"/>
<breakMatch text="/clientdependency"/>
</breakMatches>
</processor>
<processor type="UCommerce.Sitecore.Pipelines.BreakAxdExtensionProcessor, UCommerce.Sitecore" patch:source="Sitecore.uCommerce.Pipelines.HttpRequestBegin.config"/>
<processor type="Sitecore.Pipelines.HttpRequest.FilterUrlExtensions, Sitecore.Kernel">
<param desc="Allowed extensions (comma separated)">aspx</param>
<param desc="Blocked extensions (comma separated)">*</param>
<param desc="Blocked extensions that stream files (comma separated)">css,js</param>
<param desc="Blocked extensions that do not stream files (comma separated)">*</param>
</processor>
<processor type="Sitecore.ItemWebApi.Pipelines.HttpRequest.HandleActionRequest, Sitecore.ItemWebApi" patch:source="Sitecore.ItemWebApi.config"/>
<processor type="Sitecore.Pipelines.HttpRequest.QueryStringResolver, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.HttpRequest.DynamicLinkResolver, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.HttpRequest.AliasResolver, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.HttpRequest.DefaultResolver, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.HttpRequest.FileResolver, Sitecore.Kernel"/>
<processor type="Sitecore.ExperienceExplorer.Business.Pipelines.HttpRequest.PreviewResolverPipeline, Sitecore.ExperienceExplorer.Business" patch:source="Sitecore.ExperienceExplorer.config"/>
<processor type="Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel"/>
<processor type="UCommerce.Sitecore.Pipelines.ItemResolver, UCommerce.Sitecore">
<rewriteRules hint="raw:AddRules">
<rule for="categoryProduct" match="(.*)/c-(?'productCatalog'[0-9]+)/c-(?'productCategory'[0-9]+)/p-(?'product'[0-9]+)"/>
<rule for="product" match="(.*)/c-(?'productCatalog'[0-9]+)/p-(?'product'[0-9]+)"/>
<rule for="category" match="(.*)/c-(?'productCatalog'[0-9]+)/c-(?'productCategory'[0-9]+)"/>
<rule for="catalog" match="(.*)/c-(?'productCatalog'[0-9]+)"/>
</rewriteRules>
</processor>
<processor type="Sitecore.Support.Pipelines.HttpRequest.PreviewSiteResolver, Sitecore.Support.321270.321271" patch:source="Sitecore.Support.321270.321271.config"/>
<processor type="Sitecore.Mvc.DeviceSimulator.Pipelines.HttpRequest.HandleSimulationRequest, Sitecore.Mvc.DeviceSimulator" patch:source="Sitecore.MvcSimulator.config"/>
<processor type="Sitecore.Mvc.Pipelines.HttpRequest.TransferRoutedRequest, Sitecore.Mvc" patch:source="Sitecore.Mvc.config"/>
<processor type="Sitecore.ItemWebApi.Pipelines.HttpRequest.LaunchRequest, Sitecore.ItemWebApi" patch:source="Sitecore.ItemWebApi.config"/>
<processor type="Sitecore.ExperienceExplorer.Business.Pipelines.HttpRequest.ContextItemPipeline, Sitecore.ExperienceExplorer.Business" patch:source="Sitecore.ExperienceExplorer.config"/>
<processor type="Sitecore.Pipelines.HttpRequest.DeviceSimulatorResolver, Sitecore.Kernel"/>
<processor type="Sitecore.Pipelines.HttpRequest.LayoutResolver, Sitecore.Kernel"/>
<processor type="Sitecore.Mvc.Pipelines.HttpRequest.TransferMvcLayout, Sitecore.Mvc" patch:source="Sitecore.Mvc.config"/>
<processor type="Sitecore.Mvc.Pipelines.HttpRequest.TransferControllerRequest, Sitecore.Mvc" patch:source="Sitecore.Mvc.config"/>
<processor type="Sitecore.ExperienceEditor.Pipelines.HttpRequest.CheckDevice, Sitecore.ExperienceEditor" patch:source="Sitecore.ExperienceEditor.config"/>
<processor type="Sitecore.Pipelines.HttpRequest.PageEditorHandleNoLayout, Sitecore.ExperienceEditor" patch:source="Sitecore.ExperienceEditor.config"/>
<processor type="Sitecore.ExperienceExplorer.Business.Pipelines.HttpRequest.ExecuteRequest, Sitecore.ExperienceExplorer.Business" patch:source="Sitecore.ExperienceExplorer.config"/>
<processor type="Sitecore.Pipelines.HttpRequest.ExecuteRequest, Sitecore.Kernel"/>
<processor type="Sitecore.ContentTesting.Pipelines.HttpRequest.SetReadOnlySessionStateForScreenshot, Sitecore.ContentTesting" patch:source="Sitecore.ContentTesting.config"/>
</httpRequestBegin>
If there is no a better solution, here is what I've done:
public static class TemplateIDs
{
// sitecore/ucommerce item's template id
public static ID UCommerce => new ID("{AABC1CFA-9CDB-4AE5-8257-799D84A8EE23}");
}
public static class ItemExtensions
{
public static bool IsUCommerceItem(this Item item)
{
var items = item.Axes.GetAncestors();
return items.Any(x => x.TemplateID.Equals(TemplateIDs.UCommerce));
}
}
//How to use
if(Sitecore.Context.Item.IsUCommerceItem())
{
//Do your stuff
}