Hello guys,
User has no cart asigned, and if he clicks button I want to initiate new cart and add an orderline to it in the code.
Last time I did it was a while ago, now we are in DW 8.5 and things surely changed in that part of API. Was surised this didn't work :-S
this is what I have so far.
var prod = Dynamicweb.eCommerce.Products.Product.GetProductByID(prodID);
try
{
if (prod != null)
{
var newCart = new Order();
newCart.IsCart = true;
newCart.LanguageID = "LANG1";
newCart.ShopID = "SHOP1";
OrderLine newLine = new OrderLine();
newLine.SetProductInformation(prod);
newLine.Quantity = 1;
newCart.OrderLines.Add(newLine);
newCart.Save();
}
else
{
logger.addEntry("Prod Is null");
}
}
catch (Exception exc)
{
logger.addEntry(exc.ToString());
}
ProdID exists, no extra extensebility code is added to this default fresh application 8.5.0.1
Getting a nullpointer exception when calling newCart.Save();
Exceptiontext:
System.NullReferenceException: Objektreferanse er ikke satt til en objektforekomst. ved Dynamicweb.eCommerce.Orders.OrderLine.get_Price() ved Dynamicweb.eCommerce.Orders.OrderLineCollection.get_Price() ved Dynamicweb.eCommerce.Orders.Order.get_PriceBeforeFees() ved Dynamicweb.eCommerce.Orders.Order.FindPaymentFee(FeeCollection FeeCollection) ved Dynamicweb.eCommerce.Orders.Order.get_PaymentFee() ved Dynamicweb.eCommerce.Orders.Order.SaveOrder(String IDStr, Boolean saveOldVersion) ved Dynamicweb.eCommerce.Orders.Order.Save(String IDStr, Boolean saveOldVersion) ved Dynamicweb.eCommerce.Orders.Order.Save() ved CustomProject.btn_addProd_Click(Object sender, EventArgs e) i c:\Projects\CustomProject\myFile.cs:linje 37 (sorry for norwegian error) :-)
As far as I tryed to see what's the issue, there is something wrong with orderline. I did try doing something like this:
newLine.SetUnitPrice(prod.Price, true);
But it still does not help :-/
Anything I should do differently here?
Kind regards,
Dmitrij