Thank you
Ill be honest I'm a novice so I don't know if this is the correct action. I guess you understand what we are trying to achieve
I updated the CategoryTemplate to the following
@using (Html.BeginRouteForm("ConcordAddMultipleProductsToCart", FormMethod.Post))
{
<tr class = "addtocart">
<td>
<input type="submit" name="Order" value="@T("Order")" id="Order" class="productlistaddtocartbutton" />
</td>
</tr>
}
And the action which is based in both the Catalog and ShoppinCart Controller too that I took from various parts of your controllers.
//Richard Evans Description = Updating shoppingcart controller for B2T purposes as asked by Concord.
[HttpPost, ActionName("Product")]
[ValidateInput(false)]
public ActionResult ConcordAddMultipleProductsToCart(int productId, FormCollection form)
{
//current we support only ShoppingCartType.ShoppingCart
const ShoppingCartType shoppingCartType = ShoppingCartType.ShoppingCart;
string returnUrl = _workContext.CurrentCustomer.GetAttribute<string>(SystemCustomerAttributeNames.LastContinueShoppingPage);
var product = _productService.GetProductById(productId);
if (product == null)
//no product found
return Redirect(returnUrl);
int Id = 0;
foreach (var formValue in form.AllKeys)
if (formValue.StartsWith("Order-", StringComparison.InvariantCultureIgnoreCase))
Id = Convert.ToInt32(formValue.Substring("Order-".Length));
var productVariants = _productService.GetProductVariantsByProductId(productId);
if (productVariants.Count != 1){}
//get default product variant
var defaultProductVariant = productVariants[0];
//quantity to add
var qtyToAdd = defaultProductVariant.OrderMinimumQuantity > 0 ?
defaultProductVariant.OrderMinimumQuantity : 1;
//get standard warnings without attribute validations
//first, try to find existing shopping cart item
var cart = _workContext
.CurrentCustomer
.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == shoppingCartType)
.ToList();
var shoppingCartItem = _shoppingCartService
.FindShoppingCartItemInTheCart(cart, shoppingCartType, defaultProductVariant);
//if we already have the same product variant in the cart, then use the total quantity to validate
var quantityToValidate = shoppingCartItem != null ?
shoppingCartItem.Quantity + qtyToAdd : qtyToAdd;
var addToCartWarnings = _shoppingCartService
.GetShoppingCartItemWarnings(_workContext.CurrentCustomer, ShoppingCartType.ShoppingCart,
defaultProductVariant, string.Empty, decimal.Zero, quantityToValidate, false);
if (addToCartWarnings.Count > 0)
{
return Redirect(returnUrl);
}
//now let's try adding product to the cart (now including product attribute validation, etc)
addToCartWarnings = _shoppingCartService.AddToCart(_workContext.CurrentCustomer,
defaultProductVariant, ShoppingCartType.ShoppingCart,
string.Empty, decimal.Zero, qtyToAdd, true);
if (addToCartWarnings.Count > 0)
{
return Redirect(returnUrl);
}
return Redirect(returnUrl);
}
//Finsh
My Route is as follows
routes.MapLocalizedRoute("ConcordAddMultipleProductsToCart",
"cart/addproduct/{productId}",
new { controller = "Catalog", action = "ConcordAddMultipleProductsToCart" },
new { productId = @"\d+" },
new[] { "Nop.Web.Controllers" });
And nothing happens it
return Rediect(returnUrl)
as asked but no product's where inserted into the cart.
In the List I added 2 product to ProductId 1 and 3 to ProductId 2 as an small example?
Is this the correct procedure you where asking about
All help highly/humbly appreicated!