Skip to content

Conversation

@Noah-Silvera
Copy link
Contributor

Summary

In preparation for more changes to the order updater in #5872, we should rename the existing methods to better reflect what they actually do. We want update_ to encapsulate behaviour that persists, and recalculate_

Even though some of these are private methods, we are aware of a non-trivial amount of applications that override the methods of this core class, so we want to deprecate this renames before fully removing the alias'

  • OrderUpdater#update_shipment_state -> OrderUpdater#recalculate_shipment_state
  • OrderUpdater#update_payment_state -> OrderUpdater#recalculate_payment_state
  • OrderUpdater#update_payment_total -> OrderUpdater#recalculate_payment_total
  • OrderUpdater#update_order_total -> OrderUpdater#recalculate_order_total
  • OrderUpdater#update_shipment_total -> OrderUpdater#recalculate_shipment_total
  • OrderUpdater#update_item_total -> OrderUpdater#recalculate_item_total
  • OrderUpdater#update_item_totals -> OrderUpdater#recalculate_item_totals
  • OrderUpdater#update_item_count -> OrderUpdater#recalculate_item_count
  • OrderUpdater#recalculate_adjustments -> OrderUpdater#update_adjustments

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

@github-actions github-actions bot added the changelog:solidus_core Changes to the solidus_core gem label Nov 6, 2025
@codecov
Copy link

codecov bot commented Nov 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.45%. Comparing base (3660447) to head (a859efc).
⚠️ Report is 14 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6368   +/-   ##
=======================================
  Coverage   89.44%   89.45%           
=======================================
  Files         972      973    +1     
  Lines       20297    20314   +17     
=======================================
+ Hits        18155    18172   +17     
  Misses       2142     2142           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Noah-Silvera Noah-Silvera force-pushed the rename-order-updater-methods branch from ef0091f to c2a8cbf Compare November 6, 2025 19:31
@github-actions github-actions bot added the changelog:solidus_legacy_promotions Changes to the solidus_legacy_promotions gem label Nov 6, 2025
@Noah-Silvera Noah-Silvera force-pushed the rename-order-updater-methods branch from c2a8cbf to ce41518 Compare November 6, 2025 19:37
@Noah-Silvera Noah-Silvera changed the title Rename order updater methods to reflect behaviour Rename order updater methods to better reflect behaviour Nov 6, 2025
@Noah-Silvera Noah-Silvera marked this pull request as ready for review November 6, 2025 19:56
@Noah-Silvera Noah-Silvera requested a review from a team as a code owner November 6, 2025 19:56
@Noah-Silvera Noah-Silvera force-pushed the rename-order-updater-methods branch from ce41518 to 6380632 Compare November 6, 2025 19:56
Copy link
Member

@jarednorman jarednorman left a comment

Choose a reason for hiding this comment

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

This all looks good to me, but I'd love some reviews from people outside Super Good.

Copy link
Member

@tvdeyen tvdeyen left a comment

Choose a reason for hiding this comment

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

Thanks. The last commit message has a typo. Other than that, great work.

Copy link
Member

Choose a reason for hiding this comment

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

the git commit message has a typo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed the typo!

@Noah-Silvera Noah-Silvera force-pushed the rename-order-updater-methods branch from 6380632 to bc1b2b8 Compare November 7, 2025 02:10
forkata and others added 3 commits November 7, 2025 00:02
Update implies that we are persisting the change in Rails, which this
method does not do.

Co-authored-by: Adam Mueller <[email protected]>
Co-authored-by: Senem Soy <[email protected]>
Co-authored-by: Andrew Stewart <[email protected]>
Co-authored-by: Kendra Riga <[email protected]>
Co-authored-by: Sofia Besenski <[email protected]>
Co-authored-by: benjamin wil <[email protected]>
Update implies that we are persisting the change in Rails, which this
method does not do.

Co-authored-by: Adam Mueller <[email protected]>
Co-authored-by: Andrew Stewart <[email protected]>
Co-authored-by: benjamin wil <[email protected]>
Co-authored-by: Senem Soy <[email protected]>
Co-authored-by: Sofia Besenski <[email protected]>
Co-authored-by: Kendra Riga <[email protected]>
These methods don't persist so it's more accurate to say that they
recalculate the total instead of saying that they update it.

Co-Authored-By: Kendra Riga <[email protected]>
Co-Authored-By: Sofia Besenski <[email protected]>
Co-Authored-By: Chris Todorov <[email protected]>
@Noah-Silvera Noah-Silvera force-pushed the rename-order-updater-methods branch from bc1b2b8 to 289e596 Compare November 7, 2025 05:02
Copy link
Contributor

@mamhoff mamhoff left a comment

Choose a reason for hiding this comment

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

I'm a little bit confused by the last commit. So we rename the update_* methods to recalculate_*, because they don't persist - great. But then we rename recalculate_ methods to update_*, because they also don't persist? I don't know.

The other caveat I have here is that we have no protection for people who have subclassed and overridden the renamed methods. This can be done by combining the self.inherited and self.method_added hooks as I've done here: https://github.com/solidusio/solidus/blob/main/promotions/app/models/solidus_promotions/condition.rb#L104-L133. I'm not making this a condition for merging though, just a suggestion that you can go with or not.

@forkata
Copy link
Contributor

forkata commented Nov 13, 2025

I'm a little bit confused by the last commit. So we rename the update_* methods to recalculate_*, because they don't persist - great. But then we rename recalculate_ methods to update_*, because they also don't persist? I don't know.

😂 Good callout @mamhoff, I think that's a typo in the commit message. The recalculate_adjustments method definitely persists to the database because it rebuilds the adjustments on the order, so the intention with that change is to move that to the update_ naming to reflect that. We can reword the commit title and message since it deals with a single method.

This naming change is meant to help with the intention behind the methods provided by the order updater class. We have no control what anyone outside of this codebase does in their overrides, so I don't know that we need to take that into consideration, but happy to hear your thoughts if you think these methods are often overridden in apps.

There is also a minor inconsistency here worth calling out, with the top level API of this class - OrderUpdater#recalculate, but we have already decided to move away from using Order#update and OrderUpdater#update a long time ago to prevent overloading Active Record APIs. This change is in preparation for #5872 where we found it useful to distinguish between the methods that need to write to the database, vs. ones that do not when working on an in-memory version of the OrderUpdater.

The `recalculate_adjustments` method rebuilds the adjustments on the
order, so it's more accurate to say that it updates instead of saying
that it recalculates.

Co-Authored-By: Kendra Riga <[email protected]>
Co-Authored-By: Sofia Besenski <[email protected]>
Co-Authored-By: Chris Todorov <[email protected]>
@forkata forkata force-pushed the rename-order-updater-methods branch from 289e596 to a859efc Compare November 13, 2025 18:42
@mamhoff mamhoff merged commit 2c4263a into solidusio:main Nov 19, 2025
39 checks passed
@adammathys adammathys deleted the rename-order-updater-methods branch November 19, 2025 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:solidus_core Changes to the solidus_core gem changelog:solidus_legacy_promotions Changes to the solidus_legacy_promotions gem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants