November Happy Hour will be moved to Thursday December 5th.
AI OnAI Off
November Happy Hour will be moved to Thursday December 5th.
Hi Kristian,
You could try this:
public class UniverseFilterAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { var referenceConverter = ServiceLocator.Current.GetInstance<ReferenceConverter>(); var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>(); var routeHelper = ServiceLocator.Current.GetInstance<IContentRouteHelper>(); var content = routeHelper.Content; if (content == null) { return; } // Getting catalog content type var catalogContentBase = content as CatalogContentBase; if (catalogContentBase != null) { // now we have catalogContent.CatalogId // and we can find catalog from this CatalogId var catalogLink = referenceConverter.GetContentLink(catalogContentBase.CatalogId, CatalogContentType.Catalog, 0); var catalogContent = contentRepository.Get<CatalogContent>(catalogLink); // now we have catalogContent } } }
We have catalogContent now :)
Best regards,
/Son Do
Hi,
I think
var routeHelper = ServiceLocator.Current.GetInstance<IContentRouteHelper>();
var content = routeHelper.Content;
if (content == null)
{
return;
}
is what you need. content here is the content being visited, so if you compare it to the special category (I'm not sure if you meant it's catalog or node), then you can do special processing. The easiest way should be compare the content.ContentLink with the special category contentLink. (A common approach would be store that ContentLink as a property in StartPage.
Regards,
/Q
@Quan Mai,
Yes, it was just what I needed. I ended up with this code - thanks for your help.
public class UniverseFilterAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { Controller currentController = filterContext.Controller.ControllerContext.Controller as Controller; if (currentController == null) { return; } var routeHelper = ServiceLocator.Current.GetInstance<ContentRouteHelper>(); var content = routeHelper.Content; if (content == null) { return; } var catalogContentBase = content as CatalogContentBase; if (catalogContentBase == null) { return; } // My implementation went here. } }
Hi,
I need to find which category is current being visited. We have one specific category that "represents" another site and theme.
I'm not that strong with the Commerce API, yet.
What I have so far is this action filter attribute:
Thanks.