AddToCart product item (id)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 anni tempo fa
i'm trying to get the id of the current item i'm trying to put into the cart to check for attributes before adding it. i've found that _AddToCart.cshtml uses the ProductDetailsModel, but i'm not sure how to use that in another context aka action filter. could someone please provide a quick code example?
9 anni tempo fa
please someone give me a hint. this must be something very obvious i'm missing.
9 anni tempo fa
AAlexx wrote:
please someone give me a hint. this must be something very obvious i'm missing.


Maybe this what you're referring to -


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

            if (filterContext.ActionParameters.ContainsKey("shoppingCartTypeId"))
            {
                int cartTypeId = 0;
                bool hasCartTypeId= int.TryParse((filterContext.ActionParameters["shoppingCartTypeId"] ?? string.Empty).ToString(), out cartTypeId);
            }

            if (filterContext.ActionParameters.ContainsKey("productId"))
            {
                int productId = 0;
                bool hasProductId = int.TryParse((filterContext.ActionParameters["productId"] ?? string.Empty).ToString(), out productId);
            }
            
        }


You could make productId and cartTypeId instance properties to access them OnActionExecuted.  

Hope that helps, friend!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.