Developer forum

Forum » Development » Notification Order State

Notification Order State

Yung Yi Wang
Reply

In the order flows I made a new order state for failed export and filled in the notification for sending email if an export has failed.

When I set an order to this state with a handler I was expecting to receive email, but I am not receiving anything. Did I forget to configure something else??? How can I make it send notification when I changed the StateId for the order?


Replies

 
Nicolai Høeg Pedersen
Reply

You set up the mail in the backend and change the state using code, correct?

 
Yung Yi Wang
Reply

I change the state with code, but the email info I used the [manage center]>ecommerce>order flows with a new Order State where notifications are filled.

I have an ihttp handler where I process orders for export and if a order has failed to export I change the StateId. But the email notification isn't working for Order State? Can I execute the email notification for Order State manually?? And how?

 
Nicolai Høeg Pedersen
Reply

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

 

You must be logged in to post in the forum