silvershop / silvershop-core

SilverShop is an e-commerce shopping cart module for the SilverStripe CMS
http://silvershop.github.io
BSD 2-Clause "Simplified" License
113 stars 119 forks source link

Order Fulfillment State Machine #5

Open jedateach opened 12 years ago

jedateach commented 12 years ago

Storing an order's status in a single Enum db field, as has historically been the case, is to restrictive and simple for accurately storing order statuses. The idea of order 'status' should be shifted to 'state'. A state machine will help keep orders in valid states, and also help us to build systems that properly transition an order's state. State changes can be recorded in a log.

Customers, shop admins, and automatic processes can be allowed to, or prevented from doing certain things, based on the current state. Eg: tracking API can update received status automatically, but only if the order is in a 'dispatched' state.

Some states and events wont matter to store owners, therefore the system needs to be flexible. Devs should be able to incorporate their own steps (states), and transitions in the ordering fulfilment pipeline.

About state machines:

Here's a guess at some states that an order might be in:

order status-state flow scenarios

Of course there could be a number of possible shop configurations, that is different types of order fulfilment: http://en.wikipedia.org/wiki/Order_fulfillment

Requirements

Here is a guess at the requirements needed for the shop module:

Add and remove states

Because not every shop workflow is the same, there should be some leeway for adding and removing some states entirely. For example, a shop with only digital products won't have a 'processing' state.

This may be more difficult than it sounds, as I imagine things could get unstable if certain states/transitions don't exist. This could be treated as a nice-to-have for now.

Add transition event callbacks

Ability to assign custom logic to transition events. For example,

Logging all transitions

In conjunction with making notes on an order, updates (state transitions) should also be recorded.

FSM Implementations

There are various state machine implementations around that could be used. Another possible option could be to create a silverstripe module that allows turning any data object into a state machine, allowing for greater reuse.

Events that site admins will probably want to record, likely as dates rather than boolean:

All this information and events can show up in the CMS to give a clear picture where things are at. Perhaps the events are visualised along a timeline.

Related: #4

jedateach commented 12 years ago

Possibly have a 'financial status', as well as other status like 'fulfillment status'.

jedateach commented 12 years ago

Could also introduce the concept of a line being fulfilled (shipped)...or status per line.

jedateach commented 12 years ago

Documented my thoughts on improving order status functionality.

jedateach commented 12 years ago

Note: the best way to record a time:

SS_Datetime::now()->Rfc2822()
jedateach commented 11 years ago

May be useful: http://code.google.com/p/silverstripe-ecommerce/issues/detail?id=58

jedateach commented 10 years ago

see also: http://sourcemaking.com/design_patterns/state

jedateach commented 9 years ago

Here's a screenshot from prestashop's database-driven custom status setup:

screen shot 2014-12-15 at 2 36 31 pm

jedateach commented 9 years ago

May be useful for inspiration: https://github.com/silverstripe-australia/advancedworkflow

LUCKYZHOUSTAR commented 5 years ago

hello, I have some questions, for example, order system is very common, but how do we store the statemmache status for every order when we use the statemachine in our order system?