The way this works is you place a link on an external site or in an email blast like so:
http://mynopstore.com/addproducttocart/url/15/1/1
After the link is navigated to nop adds the item to the cart and redirects to /cart.
This has only been tested with 3.2 but should work for older versions.
Added to RouteProvider.cs in Nop.Web.Infrastructure
//add product to cart (without any attributes and options). used on any site.
routes.MapLocalizedRoute("AddProductToCart-Url",
"addproducttocart/url/{productId}/{shoppingCartTypeId}/{quantity}",
new { controller = "ShoppingCart", action = "AddProductToCart_Url" },
new { productId = @"\d+", shoppingCartTypeId = @"\d+", quantity = @"\d+" },
new[] { "Nop.Web.Controllers" });
Added to ShoppingCartController.cs in Nop.Web.Controllers
[HttpGet]
public void AddProductToCart_Url(int productId, int shoppingCartTypeId, int quantity, bool forceredirection = false)
{
var cartType = (ShoppingCartType)shoppingCartTypeId;
var product = _productService.GetProductById(productId);
if (product == null)
Response.Redirect("/cart");
//we can add only simple products
if (product.ProductType != ProductType.SimpleProduct)
{
Response.Redirect("/cart");
return;
}
if (product.CustomerEntersPrice)
{
Response.Redirect("/cart");
return;
}
var allowedQuantities = product.ParseAllowedQuatities();
if (allowedQuantities.Length > 0)
{
Response.Redirect("/cart");
return;
}
//get standard warnings without attribute validations
//first, try to find existing shopping cart item
var cart = _workContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == cartType)
.Where(sci => sci.StoreId == _storeContext.CurrentStore.Id)
.ToList();
var shoppingCartItem = _shoppingCartService.FindShoppingCartItemInTheCart(cart, cartType, product);
//if we already have the same product in the cart, then use the total quantity to validate
var quantityToValidate = shoppingCartItem != null ? shoppingCartItem.Quantity + quantity : quantity;
var addToCartWarnings = _shoppingCartService
.GetShoppingCartItemWarnings(_workContext.CurrentCustomer, cartType,
product, _storeContext.CurrentStore.Id, string.Empty,
decimal.Zero, quantityToValidate, false, true, false, false, false);
if (addToCartWarnings.Count > 0)
{
Response.Redirect("/cart");
return;
}
//now let's try adding product to the cart (now including product attribute validation, etc)
addToCartWarnings = _shoppingCartService.AddToCart(_workContext.CurrentCustomer,
product, cartType, _storeContext.CurrentStore.Id,
string.Empty, decimal.Zero, quantity, true);
if (addToCartWarnings.Count > 0)
{
Response.Redirect("/cart");
return;
}
//added to the cart/wishlist
switch (cartType)
{
case ShoppingCartType.Wishlist:
{
//activity log
_customerActivityService.InsertActivity("PublicStore.AddToWishlist", _localizationService.GetResource("ActivityLog.PublicStore.AddToWishlist"), product.Name);
Response.Redirect("/cart");
return;
}
case ShoppingCartType.ShoppingCart:
default:
{
//activity log
_customerActivityService.InsertActivity("PublicStore.AddToShoppingCart", _localizationService.GetResource("ActivityLog.PublicStore.AddToShoppingCart"), product.Name);
if (_shoppingCartSettings.DisplayCartAfterAddingProduct || forceredirection)
{
Response.Redirect("/cart");
return;
}
else
{
//display notification message and update appropriate blocks
var updatetopcartsectionhtml = string.Format(_localizationService.GetResource("ShoppingCart.HeaderQuantity"),
_workContext.CurrentCustomer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
.Where(sci => sci.StoreId == _storeContext.CurrentStore.Id)
.ToList()
.GetTotalProducts());
var updateflyoutcartsectionhtml = _shoppingCartSettings.MiniShoppingCartEnabled
? this.RenderPartialViewToString("FlyoutShoppingCart", PrepareMiniShoppingCartModel())
: "";
Response.Redirect("/cart");
return;
}
}
}
}