Developer forum

Forum » Development » Creating order in Addin - scheduled task question

Creating order in Addin - scheduled task question

Jan Sangill
Reply

Hi,

When I create an order via razor in the frontend - when creating an order via API - it calculates prices correctly.

However if I move the same code into an addin - then only the unitprice for the orderline is present - but the totalprices, vat prices, vat etc is not.

What am I missing to set for this to work in an addin. Do I need to set something in Context or is there something else I should be aware off?

//Jan


Replies

 
Nicolai Pedersen
Reply

Hi Jan

When calculating and creating orders there is a lot of context like currency (prices), country (VAT, delivery costs), user (Discounts and prices), language, stock locations etc. that has an affect. When you create code running out of context, it cannot calculate because of the lack of some of these things.

DW 9.8 supports this much better as the API is moving towards a "Context independent" state where these things can be handled.

I think we need to know your version and see some code in order to guide you further.

BR Nicolai

 
Jan Sangill
Reply

Hi Nikolai,

The solution is using DW 9.6.5.

This is an example of what is in code - atleast some of the important stuff:

OrderLineService orderLineService = new OrderLineService();
OrderService orderService = new OrderService();

Order order = new Order();
order.IsCart = true;

// Set general information
order.PaymentMethodId = "PAY1";
order.CustomerAccepted = true;
order.ShopId = "SHOP1";
order.LanguageId = "LANG1";
order.CurrencyCode = "DKK";
order.CurrencyName = "DKK";

Product product = Dynamicweb.Ecommerce.Services.Products.GetProductByNumber(productNo.InnerText, true);                             
OrderLine orderLine = order.CreateOrderLine(product);
orderLine.Currency = currency;
orderLine.Quantity = Convert.ToDouble(qty.InnerText);
orderLineService.SetUnitPrice(orderLine, Convert.ToDouble(price.InnerText.Replace(".", ",")), true);
                                                   
orderService.SetOrderComplete(order);
orderService.Save(order);
orderService.UpdateCartToOrder(order);

 

 
Nicolai Pedersen
Reply
This post has been marked as an answer

I am not sure it will be possible on that version. You need a newer version of Dynamicweb where the API is context independent...

Sorry!

Votes for this answer: 1
 
Jan Sangill
Reply

Hi Nicolai,

No problem. I will cheat and do it on the site via a template then:)

TY for the fast response.

//Jan

 

You must be logged in to post in the forum