Add product to customer's basket programatically

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 лет назад
Hi,

I want to add a product in my own aspx to the basket of the visitor. My files are in the same application as nopCommerce and I have referenced the nop dlls. Is there a way to add a specific product to the basket in the user session?

Thanks in advance.
11 лет назад
in Presentation/Nop.Web/Controllers/ShoppingCartController.cs file in action


[HttpPost]
        public ActionResult AddProductToCart(int productId, bool forceredirection = false)
        {


write your logic to add your product. :)
11 лет назад
Based on RouteProvider:
  routes.MapLocalizedRoute("AddProductToCart",
                            "cart/addproduct/{productId}",
                            new { controller = "ShoppingCart", action = "AddProductToCart" },
                            new { productId = @"\d+" },
                            new[] { "Nop.Web.Controllers" });

  1- from this code below
       <input type="button" value="@T("ShoppingCart.AddToCart")" class="productlistaddtocartbutton"   onclick="setLocation('@(@Url.RouteUrl("AddProductToCart", new { productId = Model.Id }))')" />

you can use Url.RouteUrl and pass the id of the product you want to add

     2-from the html side you can  do like this:

<a href='yourwebsite/cart/addproduct/id'>Add To Cart</a>
id=product id
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.