I need to check the stock of a product in the external DB before it is added to the shopcart, and I have read about “Action Filters” and I think that it can be implemented for this purpose. But my current problem is: How can I get the product that was sent/returned by the Action Filter?
My actual code
namespace Nop.Plugin.Sync.asd
{
public class DependencyRegistrar : IDependencyRegistrar
{
public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
{
builder.RegisterType<CheckWarehouseActionFilter>().As<IFilterProvider>();
}
public int Order
{
get { return 1; }
}
}
}
namespace Nop.Plugin.Sync.asd
{
public class CheckWarehouseActionFilter : ActionFilterAttribute, IFilterProvider
{
public IEnumerable<Filter> GetFilters(ControllerContext controllerContext,
ActionDescriptor actionDescriptor)
{
if (controllerContext.Controller is ShoppingCartController &&
actionDescriptor.ActionName.Equals("AddProductToCart_Details",
StringComparison.InvariantCultureIgnoreCase))
{
return new List<Filter>() { new Filter (this, FilterScope.Action, 0) };
}
return new List<Filter>();
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
//TODO: check stock
}
}
}