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

Add order_recalculated event #3553

Merged
merged 4 commits into from
May 8, 2020

Conversation

spaghetticode
Copy link
Member

@spaghetticode spaghetticode commented Mar 13, 2020

This PR adds the new event order_recalculated, also deprecating the use of order update hooks and the public method OrderUpdater#run_hooks. A conditional check has been added before running #run_hooks in order to avoid tons of not-needed deprecation messages.

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)

@spaghetticode spaghetticode force-pushed the spaghetticode/add-events branch 3 times, most recently from e079812 to 869e71c Compare March 20, 2020 10:02
@solidusio solidusio deleted a comment from houndci-bot Mar 20, 2020
@spaghetticode spaghetticode force-pushed the spaghetticode/add-events branch from 869e71c to d5a4358 Compare March 20, 2020 13:57
@spaghetticode spaghetticode marked this pull request as ready for review March 20, 2020 15:44
@spaghetticode spaghetticode self-assigned this Mar 20, 2020
@kennyadsl kennyadsl changed the title Spaghetticode/add events Add order_recalculated event Mar 24, 2020
@spaghetticode spaghetticode force-pushed the spaghetticode/add-events branch from d5a4358 to 0894a1f Compare April 10, 2020 12:21
Copy link
Member

@aldesantis aldesantis left a comment

Choose a reason for hiding this comment

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

@spaghetticode thanks! It's great to see more events in the codebase. I left a couple of small comments, and the rest looks good.

core/app/models/spree/order_updater.rb Outdated Show resolved Hide resolved
core/app/models/spree/order.rb Outdated Show resolved Hide resolved
@aldesantis aldesantis requested a review from a team April 21, 2020 08:38
@aldesantis aldesantis removed the request for review from a team April 21, 2020 08:39
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.

Great job @spaghetticode

@aldesantis
Copy link
Member

@spaghetticode one thing that just came to mind: how about adding a test for the new event?

@spaghetticode
Copy link
Member Author

@aldesantis sure 👍

The event is fired when the order recalculation process is completed,
just before saving the order.

This allows us also to deprecate the use of order's `update_hooks`.
This instance method is called in `Order#finalize!` and in
`OrderUpdater#update`. Those methods now spawn the events
`order_recalculated` and `order_finalized`, so when removing
an existing hook, one must subscribe their hook code to both
those events.

Explicit calls to `OrderUpdater#run_hooks` can be replaced with
`Spree::Event.fire :order_recalculated`.
As the method is deprecated, we should limit calling it to only when
strictly necessary, ie when there's some actual hook to be executed.
@spaghetticode spaghetticode force-pushed the spaghetticode/add-events branch from 1335dd4 to c3a1283 Compare May 8, 2020 09:28
@spaghetticode
Copy link
Member Author

@aldesantis test added. When you confirm it looks good to you I'll merge this PR.

@aldesantis
Copy link
Member

@spaghetticode looks good to me, feel free to merge!

@spaghetticode spaghetticode merged commit 28095d5 into solidusio:master May 8, 2020
@spaghetticode spaghetticode deleted the spaghetticode/add-events branch May 8, 2020 11:47
cpfergus1 added a commit to cpfergus1/solidus_klarna_payments that referenced this pull request Jun 23, 2021
Please see PR #[3553](solidusio/solidus#3553) for more information concerning this change.
cpfergus1 added a commit to cpfergus1/solidus_klarna_payments that referenced this pull request Jun 24, 2021
Please see PR #[3553](solidusio/solidus#3553) for more information concerning this change.
cpfergus1 added a commit to cpfergus1/solidus_klarna_payments that referenced this pull request Jul 6, 2021
Please see PR #[3553](solidusio/solidus#3553) for more information concerning this change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants