Developer forum

Forum » Development » order aftersave notification

order aftersave notification

Rui Silva
Reply

Hi,

Can anyone please help to understand the reason why the aftersave notification (of an order) is lauched 3 times when refreshing the first step of checkout. I've made a video (http://screencast.com/t/yRKaZYDPR0) where it shows that after making a refresh to the page are called the CartLoad notification, and then 3 times the AfterSave notification e finally the CartLoad notification.

I've also noticed using SQL profiler that these notifications correspond to three update statements executed in the server.

This is being a issue in some of our projects because we use this aftersave notification to send data to the ERP and this multiple calls are creating unnecessary calls to the  ERP.

 

Best,

Rui Silva


Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Rui

Aftersave is called everytime the order is saved (surprise!). It is not guarenteed to happen only once per page load. Various things in the process can trigger a save - i.e. discount calculation, taxes, if you update the price coming from the ERP etc.

You could very simple build in a check in your notification subscriber that it is only executed once per request by adding a value to the HttpContext.Current.Items (https://msdn.microsoft.com/en-us/library/system.web.httpcontext.items%28v=vs.110%29.aspx)

Votes for this answer: 1
 
Rui Silva
Reply

Hi Nicolai,

I understand the workarround you are explaining but I think that the best "picture" of the order it would be the last call of the aftersafe notification, and with these conditions I don't have any way to know that, right?

Only after the last call of this notification we can assume that we are looking at the final version of the order information. I can try to implement a "delayed" call to the ERP assuming that only after 1 second the DW order is correct, but in oppion it would be better to have some type of intelligence on the CMS in order to decrease the number of notifications called and avoiding this custom workarraounds to have good performance.

 

Best,

Rui Silva

 
Nicolai Høeg Pedersen
Reply

Hi Rui

Dynamicweb does not know when the last one is either - otherwise we would not call save multiple times. It is a pipeline of providers that handles different things and one of those steps could stop the process. It would be a bigger redesign of that pipeline to make sure order.save is only called once per request. Of course we want to limit the amount of save operations.

BR Nicolai

 

You must be logged in to post in the forum