Posted on 11/05/2016 14:43:03
If you set Order.StateID to any value, the order will be in a changed state triggering mails and notifications when save is called.
If you do it from a ihttp handler, there might be some httpcontext/session issues that can cause this to not work. The email is send using a pageview instance, and that might be the cause if it cannot exist. So if you add the IRequiresSessionState marker interface on your handler, you might solve the problem.
Else, What happens if you execute your code in a regular .aspx in a browser? And can you check that you get a Order.State.Changed notification fired when you change the state (fires before the mail is sent)?
You can send the mail manually - this is our code that does that (It calls a method, SendTo that you can find on Order.SendTo:
Dim state As OrderState
If Me.IsQuote AndAlso Not Me.Complete Then
state = Dynamicweb.Ecommerce.Orders.OrderState.getQuoteStateByID(StateID)
Else
state = New OrderState(StateID)
End If
If Not state Is Nothing AndAlso ((state.SendToCustomer AndAlso Not String.IsNullOrEmpty(state.MailTemplate) AndAlso Not String.IsNullOrEmpty(CustomerEmail)) OrElse
(state.OthersRecipients.Count > 0 AndAlso Not String.IsNullOrEmpty(state.OthersMailTemplate))) Then
Dim senderMail As String = state.MailSender
If Not EmailHandler.ValidateEmail(senderMail) Then
senderMail = Dynamicweb.Configuration.SystemConfiguration.Instance.Get("/Globalsettings/Settings/CommonInformation/Email")
If Not EmailHandler.ValidateEmail(senderMail) Then
senderMail = "noreply@dynamicsystems.dk"
End If
End If
Dim cultureName As String = ""
If IsNothing(Dynamicweb.Frontend.PageView.Current()) Then
Dim ol As OrderLine = Me.OrderLines.FirstOrDefault(Function(x) x.PageID > 0)
If Not IsNothing(ol) Then
Dim pageService As IPageService = ServiceLocator.Current.GetPageService()
Dim cartPage As Page = pageService.GetPage(ol.PageID)
cultureName = cartPage.Area.Culture
End If
End If
If state.SendToCustomer AndAlso Not String.IsNullOrEmpty(state.MailTemplate) AndAlso Not String.IsNullOrEmpty(CustomerEmail) Then
Dim tmpl As New Template(state.MailTemplate, cultureName)
SendTo(Nothing, state.MailSubject, CustomerEmail, senderMail, state.MailSenderName, tmpl)
End If
If state.OthersRecipients.Count > 0 AndAlso Not String.IsNullOrEmpty(state.OthersMailTemplate) Then
Dim tmpl As New Template(state.OthersMailTemplate, cultureName)
SendTo(Nothing, state.MailSubject, state.OthersRecipients, senderMail, state.MailSenderName, tmpl)
End If
End If