Developer forum

Forum » Development » Order status email generation failed when status change from code

Order status email generation failed when status change from code

Shiwanka Chathuranga Dynamicweb Employee
Shiwanka Chathuranga
Reply
We are changing order status from another function from shipping provider and that time email is not generated. but status changed correctly.
when we change that status manually from DW backend email is generated without any issue
 
Code :
order.StateId = "OS3";
orderService.Save(order);
 
Error :
Object reference not set to an instance of an object. >> at Dynamicweb.Ecommerce.Frontend.Renderer.RenderProduct(Product product, Boolean extendedProperties, Template template, Int32 loopCounter, Boolean renderRelated, String productUrl, Int32 quantity, Int32 wishListId, Boolean renderPublicList, Boolean isRecursiveCall, Lazy`1 categoryFieldSorting, Int32 orderLineOfProductCount, RenderingContext renderingContext, String unitId)
at Dynamicweb.Ecommerce.Frontend.Renderer.RenderOrderLine(OrderLine orderLine, Template template, RenderingContext renderingContext)
at Dynamicweb.Ecommerce.Frontend.Renderer.RenderOrderLines(OrderLineCollection orderLines, Template parentTemplate, String loopName, RenderingContext renderingContext)
at Dynamicweb.Ecommerce.Frontend.Renderer.RenderOrderDetails(Template template, Order order, Boolean extendedProperties, OrderTemplateExtenderContext orderContext)
at Dynamicweb.Ecommerce.Frontend.Renderer.RenderOrder(Order order, Template template, Boolean extendedProperties, Int32 stepNumber, OrderTemplateExtenderContext orderContext)
at Dynamicweb.Ecommerce.Orders.OrderService.SendEmail(Order order, PageView& pageView, String subject, IEnumerable`1 toMailAddresses, String fromMailAddress, String fromMailName, Template& mailTemplate)
at Dynamicweb.Ecommerce.Orders.OrderService.SendStateChangedEmail(Order order, OrderState state, PageView pageView)
at Dynamicweb.Ecommerce.Orders.OrderService.NotifyOrderStateChanged(Order order)
at Dynamicweb.Ecommerce.Orders.OrderService.Save(Order order, Boolean saveOldVersion)
at Dynamicweb.Ecommerce.Shipping.GrabExpress.Webhook.GrabExpressController.Webhook(DeliveryWebhookResponseModel model)

Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Something on a product on an orderline seems to be having a missing value - or a missing renderingContext (are you changing the state in code that is not httpContext?) 

You need to add a debugger and add debugging symbols for Dynamicweb.Ecommerce so we can get a line number where the exception happens.

Also can you provide the DW version?

BR Nicolai

 
Shiwanka Chathuranga Dynamicweb Employee
Shiwanka Chathuranga
Reply

its latest DW  9.15.13

 
Shiwanka Chathuranga Dynamicweb Employee
Shiwanka Chathuranga
Reply

issue comes from OrderLines loop

foreach (LoopItem orderline in GetLoop("OrderLines"))

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Shiwanka

I need a bit more info to understand. Where do you change the orderstate from? And in what context is it executed - schedule, pageview or something else?

 
Shiwanka Chathuranga Dynamicweb Employee
Shiwanka Chathuranga
Reply

Order state change from webapi controller and that uses dwapi APIRegistrationBase

used OrderService to save the order

 
Shiwanka Chathuranga Dynamicweb Employee
Shiwanka Chathuranga
Reply

any update?

 
Andrew Rushworth
Reply

I'm having the same issue as the OP.

If I change the order state via the Admin portal, the email gets sent without issue, but when i change the state via code it gives error in Dynamicweb.Ecommerce.Frontend.Renderer.RenderProduct as per original post.

 

Maybe there is a special way to create the order object that pulls in a more complete object than using the Ecommerce.Services.Orders.GetById() - maybe something is not populated by this method.

DW v 9.15.13

 

 
Andrew Rushworth
Reply

It looks like Dynamicweb.Admin is doing the exact same thing but it works in there, just not when using a scheduled task.

Dynamicweb.Ecommerce.Services.Orders.GetById();
Dynamicweb.Ecommerce.Services.Orders.Save();

Using the Designs/Rapido/eCom7/CartV2/Mail/Order.cshtml template.
Just can't see why there would be a difference between the Admin code and using the exact same code in a library.

 
Shiwanka Chathuranga Dynamicweb Employee
Shiwanka Chathuranga
Reply

Hi Andrew

can you try latest 9.15.17

as i remember this was already fixed

 
Andrew Rushworth
Reply

I upgraded to 9.15.17 and still getting issue.

If you change the status in the Admin, it works, but not when running same process via code.

 

You must be logged in to post in the forum