Developer forum

Forum » Development » Make a copy of an orderline

Make a copy of an orderline


Reply

Hi,

I'm trying to make a module which can add a copy of an existing orderline to an existing order.
The module is a backend module, so it need to work without any frontend sessions set.

I've tried with the approach below:

OrderLine Orderline = new OrderLine( "OL100" );

OrderLine obj = new OrderLine();
obj.BOM = Orderline.BOM;
obj.BOMItemID = Orderline.BOMItemID;
obj.Date = DateTime.Now;
obj.DiscountID = Orderline.DiscountID;     
obj.Modified = Orderline.Modified;
obj.Order = Orderline.Order;
obj.OrderID = Orderline.OrderID;
obj.OrderLineFieldValues = Orderline.OrderLineFieldValues;
obj.PageID = Orderline.PageID;
obj.ParentLineID = Orderline.ParentLineID;     
obj.Product = Orderline.Product;
obj.ProductID = Orderline.ProductID;
obj.ProductName = Orderline.ProductName;
obj.ProductNumber = Orderline.ProductNumber;
obj.ProductVariantID = Orderline.ProductVariantID;
obj.ProductVariantText = Orderline.ProductVariantText;
obj.Quantity = Orderline.Quantity;
obj.Reference = Orderline.Reference;
obj.Type = Orderline.Type;
obj.UnitID = Orderline.UnitID;
obj.SetUnitPrice( 100 );
obj.Save();


But it gives me an "Object reference not set to an instance of an object." error in the save method.

I also tried this:

OrderLine Orderline = new OrderLine( "OL100" );
Orderline.Save();

Which gives my the same error.

Any hint on how i archieve this? i could copy the orderline directly in the database, but i'd like to use the API if possible.

//Martin

 


Replies

 
Reply

I get an error when i try to get the prices from my orderline.

This line gives me an error
double test = Orderline.Price.PriceWithVAT;See the stacktrace here:
 

[NullReferenceException: Object reference not set to an instance of an object.]
   Dynamicweb.eCommerce.Orders.OrderLine.get_Price() +14


 


I would assume that it's because the price calculation tries to access the current Context, which is not available in the backend.

How can i avoid this? Can i set a fake Context for the backend?

//Martin
 
Reply
Hi Martin

I think the OrderLine.Order is null. Try using either
new OrderLine(orderlineID, order) or
create the order by new Order(orderID) and use Order.OrderLines.

 - Lasse

 

You must be logged in to post in the forum