Deprecate raising an exception when order and line item currencies mismatch #3456
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The current behavior is to raise an exception when the currency of the price that we are trying to set on a line item mismatches with the order currency.
However, this is creating issues because it's raising also when the currency is valid. This happens because we don't have control of the order used by Rails to set attributes on the LineItem instance and
order is still nil/unset when
money_price=
is executed.This PR allows to conditionally avoid the raise, switching the behavior to a standard Rails validation. This is better because, at validation time, we have the instance with all the attributes set and we are sure to be able to perform the right check.
The validation behavior is the new default for new installations and the
raise
behavior has been deprecated.This PR has the side effect to restore passing the
options
attribute to a line_item to set attributes that are needed for pricing changes. We had this feature broken (with pending tests) since a past security change.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)