Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable order state machine and reduce the number of possible transitions #3542

Merged
merged 2 commits into from
Jul 10, 2020

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Mar 6, 2020

This PR can be divided into two logical parts that are interdependent and
breaking each one in their way. These parts are described in detail later.

Make Order state machine configurable

In 7c4f82c, all relevant state machines except for the order one have
been extracted into modules. This performs the same exercise for the
order state machine. A lot of this code is deeply interlinked with the
rest of the system, so you'd have to take lots of care when replacing
this; but it should be possible nonetheless.

The new state machine is named Spree::Core::StateMachines::Order and
includes the same code of the old one.

The newly named state machine is active on new stores generated from
scratch and in Solidus tests, but old stores will still use the old one,
unless the preference Spree::Config.use_legacy_order_state_machine is
explicitly set to false.

When using the old named state machine a deprecation warning will be
printed at boot time, as Solidus 3.0 will start using the new order state
machine by default.

Reduce the number of new order state machine transitions

This removes many, many transitions from the Order state machine definitions
included in Spree::Core::StateMachines::Order, allowing us to reason more
clearly about what the system is supposed to be doing and when.

This new state machine definition is not active yet on existing stores, but
will become standard from Solidus 3.0.

The legacy state machine definitions from Spree::Order::Checkout are left
untouched, so old stores can continue to use them.

A bunch of transitions have been removed, and now an order can transition to:

  • Canceled only when Complete;
  • Awaiting Return only when Complete;
  • Returned only when Complete or Awaiting Return.

This change was initially proposed with #3532 but for convenience it
has been included directly here as the original PR, being a breaking change, was
not mergeable in isolation without the premise of the first part of this PR. Please
consider taking a look at the original PR for the interesting discussion.

Checklist:

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)
  • I have attached screenshots to this PR for visual changes (if needed)

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's still WIP, but I left some comments, thanks!

core/lib/spree/core/state_machines.rb Outdated Show resolved Hide resolved
core/lib/spree/core/state_machines/order.rb Show resolved Hide resolved
@aldesantis aldesantis added this to the 2.11 milestone May 22, 2020
@aldesantis
Copy link
Member

@mamhoff it would be awesome to get this in 2.11, which is the last release of the 2.x branch. The idea is to merge this in 2.11 and deprecate the old state machine module, then remove it completely in 3.0.

@spaghetticode
Copy link
Member

I can try to move this forward, if @mamhoff agrees.

@mamhoff
Copy link
Contributor Author

mamhoff commented May 31, 2020 via email

@seand7565
Copy link
Contributor

Quick note here, to reflect discussion on the issue: When this is merged, we can close #1576

@spaghetticode spaghetticode force-pushed the configurable-order-state-machine branch from 0f1ea10 to 90e6fcf Compare June 5, 2020 09:11
@spaghetticode spaghetticode self-assigned this Jun 5, 2020
@spaghetticode spaghetticode added type:enhancement Proposed or newly added feature Important Change labels Jun 5, 2020
@spaghetticode spaghetticode force-pushed the configurable-order-state-machine branch 3 times, most recently from 2ece35b to 2e7c5db Compare June 5, 2020 09:52
@spaghetticode spaghetticode requested a review from a team June 5, 2020 14:48
@spaghetticode spaghetticode changed the title Make Order state machine configurable Make Order state machine configurable and reduce possible transitions Jun 5, 2020
@spaghetticode spaghetticode changed the title Make Order state machine configurable and reduce possible transitions Make Order state machine configurable and reduce the number of possible transitions Jun 5, 2020
@aldesantis
Copy link
Member

aldesantis commented Jun 10, 2020

Putting this on hold because @kennyadsl had some opinions about potentially deprecating and then removing remove_checkout_step and methods.

@spaghetticode spaghetticode changed the title Make Order state machine configurable and reduce the number of possible transitions Configurable order state machine and reduce the number of possible transitions Jun 12, 2020
@kennyadsl
Copy link
Member

I hope to be able to talk about this in our Core Team meeting this week.
Anyway, we just merged #3658 and this probably requires some extra work to also backport the changes introduced there.

mamhoff and others added 2 commits June 26, 2020 12:31
In 7c4f82c, all relevant state machines except for the order one have
been extracted into modules. This performs the same exercise for the
order state machine. A lot of this code is deeply interlinked with the
rest of the system, so you'd have to take lots of care when replacing
this; but it should be possible nonetheless.

The new state machine is named Spree::Core::StateMachines::Order and
includes the same code of the old one.

The newly named state machine is active on new stores generated from
scratch and in Solidus tests, but old stores will still use the old one,
unless the preference `Spree::Config.use_legacy_order_state_machine` is
explicitly set to `false`.

When using the old named state machine a deprecation warning will be
printed at boot time, as Solidus 3.0 will start using the new order state
machine by default.
This removes many, many transitions from the Order state machine definitions
included in Spree::Core::StateMachines::Order, allowing us to reason more
clearly about what the system is supposed to be doing and when.

This new state machine definition is not active yet on existing stores, but
will become standard from Solidus 3.0.

The  legacy state machine definitions from Spree::Order::Checkout are left
untouched, so old stores can continue to use them.

A bunch of transitions have been removed, and now an order can transition to:

  * Canceled only when Complete;
  * Awaiting Return only when Complete;
  * Returned only when Complete or Awaiting Return.
@spaghetticode spaghetticode force-pushed the configurable-order-state-machine branch from 41bf48b to 98099f0 Compare June 26, 2020 12:29
@spaghetticode
Copy link
Member

spaghetticode commented Jul 1, 2020

I explored the idea of adding a deprecation to the constant Spree::Order::Checkout but both ActiveSupport::Deprecation::DeprecatedConstantAccessor and ActiveSupport::Deprecation::DeprecatedConstantProxy require a replacement constant that will be used instead of the deprecated one, as rightfully predicted by @kennyadsl, so they don't fit here. In the end, I think we can be happy with the deprecation at https://github.com/solidusio/solidus/pull/3542/files#diff-b80f3499d79adcd431c150b9964453feR72.

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks, Andrea!

@kennyadsl kennyadsl merged commit 7073fd9 into solidusio:master Jul 10, 2020
aldesantis added a commit to solidusio/solidus_subscriptions that referenced this pull request Sep 24, 2020
In Solidus 2.11, it isn't possible to cancel an order that hasn't been
completed anymore[1], which causes our failure dispatchers to fail when
they call `order.cancel!`.

To work around the issue, we're now only cancelling if the state machine
allows us to (i.e., on Solidus <= 2.10 and in customized state machines).
If the order cannot be cancelled, we skip the transition silently.

[1]: solidusio/solidus#3542
aldesantis added a commit to solidusio/solidus_subscriptions that referenced this pull request Sep 24, 2020
In Solidus 2.11, it isn't possible to cancel an order that hasn't been
completed anymore[1], which causes our failure dispatchers to fail when
they call `order.cancel!`.

To work around the issue, we're now only cancelling if the state machine
allows us to (i.e., on Solidus <= 2.10 and in customized state machines).
If the order cannot be cancelled, we skip the transition silently.

[1]: solidusio/solidus#3542
aldesantis added a commit to solidusio/solidus_subscriptions that referenced this pull request Sep 25, 2020
In Solidus 2.11, it isn't possible to cancel an order that hasn't been
completed anymore[1], which causes our failure dispatchers to fail when
they call `order.cancel!`.

To work around the issue, we're now only cancelling if the state machine
allows us to (i.e., on Solidus <= 2.10 and in customized state machines).
If the order cannot be cancelled, we skip the transition silently.

[1]: solidusio/solidus#3542
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement Proposed or newly added feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants