Posted on 31/08/2023 16:33:16
Hi Alexandru,
Looking at your code, depends if the order is already in that particular state.
Dynamicweb tracks the StateId property of an Order, and only if it changes, then it kicks off notification emails and such. In other words, simply doing o.StateId = stateId, will not ensure the emails are sent. It can be a bit of a hack, but you could reset the o.StateId first, and then set it to the desired state. That would trigger it.
I can't say this is the best solution, but it's our most recent/current approach:
- We have a scheduled task to pick up orders that have been manipulated through a data activity (aka Integration job)
- We use a flag to determine what orders need to be "triggered"
i.e. RequiresUpdate=true
- We instantiate the order (using Services)
- We update the flag (and may do some funky stuff to reset/update the stateId
- We call Services.Orders.Save(order)
So it's pretty much what you plan to do, but more specifically through a Scheduled task. You could likley do it using a Notification subscriber at the end of the activity runs. The reason why we use a Scheduled task add in is because it provides some configuration options so we don't have to tweak code between projects.
Hope this helps,
Nuno Aguiar