Hi Andy
I know you said that this is getting to big for this thread I will be writing on a seperate forum page. I'm aware you are busy,
I have wrote the new method as follow's in the Nop/Web/Controllers/ShoppingCart.cs
[HttpPost]
public ActionResult AddMultipleProductToCart(int productId)
{
//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 RedirectToAction("Index", "Home");
var productVariants = _productService.GetProductVariantsByProductId(productId);
if (productVariants.Count != 1)
{
{
return Redirect(returnUrl);
}
}
//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);
}
There seems to be no error's when debugging.
I'm slightly confused about the view.
I have kept the ProductBox but done allot of alteration
Using the The Category.Template I Have the following code
@foreach (var product in Model.Products)
{
<tr>
@Html.Partial("_ConcordProductBox", product)
</tr>
}
<td class = "addtocart">
<input type="button" value="@T("Order")" class="productlistaddtocartbutton" onclick="setLocation('@(@Url.RouteUrl("ConcordAddMultipleProductsToCart", new { productId = Model.Id }))/' + $('#quantity_').val())" />
</td>
I have added the following route.
//Richard Evans -- Description Add Multiple Products to Cart 17/8/2012
//Start (Test - Revist)
routes.MapLocalizedRoute("ConcordAddMultipleProductsToCart",
"cart/addproduct/{productId}/quantity/{quantity}",
new { controller = "Catalog", action = "ConcordAddMultipleProductsToCart" },
new { productId = @"\d+" },
new[] { "Nop.Web.Controllers" });
//Finish
On excuting it becomes undefined In the source with the following error
Server Error in '/' Application.
--------------------------------------------------------------------------------
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /undefined
and in the Source View I have the following
<input type="button" value="Order" class="productlistaddtocartbutton" onclick="setLocation('/' + $('#quantity_').val())" />
Is there away I can define the Multiple ProductId with paired Quantity's with this input button.
I have looked at various List view's in the Admin area but they tend to use MVC.Telerik UI. But I thought it would be more productive to use basic HTML/CSS/Jquery.
I know you said you where busy but If you help it would be highly regarded.
Kind Regards
Richard.