checkout_flow
DSL, described in the Checkout Flow DSL section below.
Spree::Auth::Config[:registration_step]
configuration setting)Spree::Order
state machine. The spree_auth_devise
gem (an extension that comes with Spree by default) adds the check_registration
before filter to all actions of Spree::CheckoutController
(except for obvious reasons the registration
and update_registration
actions), which redirects to a registration page unless one of the following is true:
Spree::Auth::Config[:registration_step]
preference is not true
allow_guest_checkout
preference to change the default setting.
confirmation_required?
method in Spree::Order
.
Spree::Order
state machine is the foundation of the checkout process. Spree makes use of the state_machines gem in the Spree::Order
model as well as in several other places (such as Spree::Shipment
and Spree::InventoryUnit
.)
The default checkout flow for the Spree::Order
model is defined in app/models/spree/order/checkout.rb
of spree_core.
An Spree::Order
object has an initial state of ‘cart’. From there any number of events transition the Spree::Order
to different states. Spree does not have a separate model or database table for the shopping cart. What the user considers a “shopping cart” is actually an in-progress Spree::Order
. An order is considered in-progress, or incomplete when its completed_at
attribute is nil
. Incomplete orders can be easily filtered during reporting and it’s also simple enough to write a quick script to periodically purge incomplete orders from the system. The end result is a simplified data model along with the ability for store owners to search and report on incomplete/abandoned orders.
For more information on the state machines gem please see the [README](https://github.com/state-machines/state_machines\)
valid_zip_code?
method, and then tell the state machine to run this method before that transition, placing this code in a file called app/models/spree/order_decorator.rb
:
delivery
step if valid_zip_code?
returns false.
Spree::Order
class.
The default checkout flow for Spree is defined like this, adequately demonstrating the abilities of this new system:
remove_transition
method of the Checkout DSL. The resulting transitions between states look like the image below:
These two helper methods are provided on Spree::Order
instances for your convenience:
checkout_steps
: returns a list of all the potential states of the checkout.has_step?
: Used to check if the current order fulfills the requirements for a specific state.checkout_steps
method, which will return the steps in an array.
insert_checkout_step
and remove_checkout_step
helpers respectively.
The insert_checkout_step
takes a before
or after
option to determine where to insert the step:
remove_checkout_step
will remove just one checkout step at a time:
checkout_flow
helper: