I am adding custom products to the DW Basket and it works just fine. Except for this one situation:
When I add products to the basket and go to the basket and empty it and I try to add products to the basket again.
The first attempt fails with this exception:
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.ArrayList.ArrayListEnumeratorSimple.MoveNext()
at Dynamicweb.eCommerce.Orders.OrderLineCollection.get_Price()
at Dynamicweb.eCommerce.Orders.Order.get_PriceBeforeFees()
at Dynamicweb.eCommerce.Orders.Order.get_ShippingFee()
at Dynamicweb.eCommerce.Orders.Order.Save(String IDStr)
at Dynamicweb.eCommerce.Orders.Order.Save()
at CustomModules.MyCart.BasketTester.AddProductToCart(String ProductNumber, Int32 amount)
the code that raises the exception is:
Order o = Dynamicweb.eCommerce.Common.Context.Cart;
if ( o == null )
{
o = new Order();
o.CustomerAccessUserID = dwUser.UserID;
o.CustomerAccessUserUserName = dwUser.UserName;
o.CustomerNumber = objUser.Number;
o.Date = DateTime.Now;
o.IP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
o.IsCart = true;
o.StateID = OrderState.getDefaultOrderstate().get_Item( 0 ).ID;
o.LanguageID = HttpContext.Current.Request["LANG"];
o.ShopID = HttpContext.Current.Request["SHOP"];
o.StepNum = 1;
o.Save();
}
string productName =ProductNumber;
// Add Product As OrderLine
OrderLine ol = new OrderLine();
ol.Date = DateTime.Now;
ol.Order = o;
ol.OrderID = o.ID;
ol.ParentLineID = "";
ol.ProductID = ProductNumber;
ol.ProductName = productName;
ol.ProductNumber = ProductNumber;
ol.Quantity = amount;
ol.Type = "0";
ol.UnitPrice = new Dynamicweb.eCommerce.Prices.PriceInfo() { PriceWithoutVAT = 0, PriceWithVAT = 0 };
o.OrderLines.Add( ol );
o.Save();
and the error is at the line where I call o.Save() the second time (marked RED)
After I have got the exception I can add products to the order, so my thoughts is that the "Empty basket" thing is doing some nasty stuff to the Dynamicweb.eCommerce.Common.Context.Cart's OrderLines
Does anyone have a workaround or fix for this issue?