sitecore8 - How to check if Context.Item is uCommerce item or Sitecore item -
i developing language switch sitecore-ucommerce solution , using default ucommerce item resolver , urlservice nice urls. have urls http://sitename/catalogname/productname/c-xx/p-yy.
then every sitecore 'page' item use linkmanager.getitemurl(context.item, options) languageembedding.always option.
now, if context.item ucommerce item, url http://sitename/nl/sitecore/ucommerce/products/3/34/productname/, not caught ucommerce item resolver , have document not found error.
so need check before if context.item ucommerce item , use urlservice instead of linkmanager.
question: there in ucommerce class templateids similar sitecore.templateids? way check if item derives base ucommerce product template.
related question: how can embed language in ucommerce nice urls?
here 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 ignored http request pipeline --> <processor type="sitecore.fxm.pipelines.httprequest.ignorebundleentries, sitecore.fxm" patch:source="sitecore.fxm.bundle.config"/> <!-- register bundles on first request --> <processor type="sitecore.fxm.pipelines.httprequest.onrequestbundleregistrarprocessor, sitecore.fxm" patch:source="sitecore.fxm.bundle.config"> <bundles hint="list:addbundle"> <!-- fxm client javascript bundle - see registration pipeline below. requires current sitecore instance host name when creating bundle, must generated part of 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 stream files (comma separated)">css,js</param> <param desc="blocked extensions 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 no better solution, here 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 use if(sitecore.context.item.isucommerceitem()) { //do stuff }
Comments
Post a Comment