mercredi 8 novembre 2017

How to make immutable Orders

I have a shopping cart/e-commerce website with configurable price rules that get into play in various situations(user has role, user has cookie, user is anonymous, user has item X in cart, user has selected carrier XYZ ...) and places(product, shipping method, payment method, cart..). There is configurable checkout flow(steps, each step can have different "widgets"...).

So the process from visiting the site for the first time to completing an order contains a lot of logic and data flows which influence the final pricing.

With this in mind I would like to make orders immutable(beside very few attributes that can change into specific state, like paid/unpaid, and even that can be done only once - order can be paid only once).

But the issue in the e-commerce world is that admins will want to edit orders. For example a customer will call in that he wants a new item added/removed from order he just placed and so on.

By allowing admin to alter the order, the pricing rules and everything that lead to the final order state becomes, basically, invalid. For example, an order of 1 item X will cost the customer 100$ but if the quantity is changed to 2 there should be a discount of 20% on the second item so the total should be 180$. But since the checkout/order flow did not take place again, the total will be 200$.

So to avoid this I am thinking of making orders immutable. If similar case occurs, the order should be cancelled and based on data from it a new one should be created. This is easy, but I cannot ask admin to follow the checkout process manually because it would take too much time even with pre-filled data. Not to mention that setting the original contexts is quite impossible.

So I wonder how should I design the process so that it is repeatable in a correct way?

Aucun commentaire:

Enregistrer un commentaire