Developer forum

Forum » Ecommerce - Standard features » How do I prevent an order from finalizing?

How do I prevent an order from finalizing?

Peter Leleulya
Reply

Hi guys,

I have a situation where I do all sorts of fancy stuff in the EcomCartOrderIsPassedToCheckoutHandlerObserver
As a last step in the EcomCartOrderIsPassedToCheckoutHandlerObserver I send the order to another system.

Now I need to implement a new feature.
The passing the order to the other system now gives me a response and I need to react to this response.
If it tells me the order couldn't be processed on their end I still want to show the following (last) cart page (on which I want to show a corresponding message), but I do not want the order to be finalized.

I saved the response on the order, so I can use it in the last cart page to show a message, that works.
I tried to keep the order open by setting:

order.IsCart = true;
order.Complete = false;
order.Save();

But that results into a completed cart with the IsCart set to true sad

I noticed there are observer templates called "CartCheckoutDoneIsCompleteObserver" and "CartCheckoutDoneIsNotCompleteObserver", so I think the Dynamicweb order completion functionality is somewhere between these observer moments. My settings to "uncomplete" the order in the EcomCartOrderIsPassedToCheckoutHandlerObserver is too early.
But I can't figure out how to prevent this action and still end up on a page after the EcomCartOrderIsPassedToCheckoutHandlerObserver being able to show a message and give the customer the opportunity to do things with his cart. (now they end up with: "whoops something went wrong" and an empty cart)

Can anyone push me in a right direction here?


Replies

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

Hi Peter

It is the checkouthandler that completes the order. It has a method, CheckoutDone, that sets the checkout to be done - but not always sets completed to true. That depends on what the checkouthandler does.

So I think you should move your code from the observer you have, into your own checkout handler in the StartCheckout method. If everything is OK when processing your order, you call SetOrderComplete first followed by CheckoutDone. If your order fails, you only call CheckoutDone (but not SetOrderComplete). The last call you make is to RedirectToCart(order) - that should give you the receipt page.

Nicolai

Votes for this answer: 1
 
Peter Leleulya
Reply

Thanx for the advice Nicolai!
I think I managed to do as you described.

 

You must be logged in to post in the forum