Adding a ActionFilter to the Product Details controller

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 yıl önce
I'm trying to hide the "Add To Cart" button based on certain criteria, so i've created a plugin with the class below but it's not hitting any of my brake points.
I've added the class to my DependencyRegistrar but it's still not firing, can someone spot where i've gone wrong?

builder.RegisterType<ProductActionFilter>().As<IFilterProvider>().InstancePerLifetimeScope();


    public class ProductActionFilter : ActionFilterAttribute, IFilterProvider
    {
        public IEnumerable<Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
        {
            if (controllerContext.Controller is ProductController
                && actionDescriptor.ActionName.Equals("ProductDetails", StringComparison.InvariantCultureIgnoreCase))
            {
                return new List<Filter>()
                {
                    new Filter(this, FilterScope.Action, 0)
                };
            }
            return new List<Filter>();
        }

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
        }

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {

            base.OnActionExecuted(filterContext);
        }
    }
7 yıl önce
Can I confirm with you that your ProductController refers to the one in Nop.Web? There is also a ProductController in Nop.Admin.
7 yıl önce
Yes it was the correct controller.... for some reason my IDependencyRegistrar class was being cached due to an error in another project so it was still using the order of 0 instead of the amendment of 99.

For anyone else looking at this post, the code is correct and working.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.