-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 ability to run validations in order updater #3645
Add ability to run validations in order updater #3645
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mamhoff @kennyadsl thanks! 👍
core/lib/spree/core/engine.rb
Outdated
@@ -64,6 +64,15 @@ class Engine < ::Rails::Engine | |||
caller | |||
) | |||
end | |||
|
|||
if Spree::Config.run_order_validations_on_order_updater == false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for not allowing also other falsy values (ie. nil
) here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it can be nil
or any other thing since it's initialized with true
as default. Of course, unless you initialize this with a non-boolean value. Anyway, the only accepted value that should not raise a deprecation error is true
so I'm going to change this, thanks!
@@ -186,7 +186,7 @@ def update_item_total | |||
end | |||
|
|||
def persist_totals | |||
order.save!(validate: false) | |||
order.save!(validate: Spree::Config[:run_order_validations_on_order_updater]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, is there a reason for choosing the []
syntax here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, the .
version is the one used in the codebase. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, though I'm curious about the answers to @spaghetticode's questions.
Prior to this commit, when running the order updater with invalid associated records, these records would be saved along with the order. This updates the order updater such that it actually raises when called with an invalid order.
This spec would start with an invalid order, which should not happen in an actual sitation.
We know at this point that adding -1 to the order won't work. Let's not try.
We know at this point the merged order won't be valid. Don't persist it.
In this spec, the spec setup assumed that it could get ahead with a non-persisted store, which never happens IRL.
In real life, completed orders have an email address.
This allows to keep the old behavior and easily switch to the new one. The default is false, which is what is currently happening.
Also, this commit adds the new default value to the spree.rb initializer, that will be used when installing new Solidus applications and to the dummy app that will run specs with the new value set to the new behavior's value.
The order is not valid without a store and this way the test is more reliable, it reflects more closely what happens IRL.
0c345dd
to
1a9af09
Compare
Description
This PR is a continuation of the old #2208.
It's only adding to the original work a preference that allows people to knowingly switch to the new behavior with:
It also adds a deprecation warning booting the application if the value used for the preference is false.
Checklist:
[ ] I have updated Guides and README accordingly to this change (if needed)[ ] I have attached screenshots to this PR for visual changes (if needed)