-
-
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
Improve the extensibility of Rules::ItemTotal #3431
Improve the extensibility of Rules::ItemTotal #3431
Conversation
da25ca6
to
7fa99c7
Compare
7fa99c7
to
616e1a7
Compare
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.
@elia, thanks for the PR, I left a comment and have some concerns about the extendability approach: we are basically changing the class to let some of its logic easily extendable, suggesting users to override private methods in order to configure it. I think this is not a practice that we should promote since I'd prefer to be free to change/remove private methods in core classes without any concern. The basic solution could be moving those methods in the public scope, but I'm wondering if there's a better design for this.
The original drive for this PR was to enable creating rules such as the following: class ItemTotalBeforeTax < ItemTotal
# Rely on the item total with the adjustments already applied
def total_for(order)
order.item_total_before_tax
end
end and module ItemTotalDecorator
def operators_map
super.merge(eq: :==)
end
Spree::Promotion::Rules::ItemTotal.prepend self
end where it's really easy to cherry-pick just the method you want to target. |
616e1a7
to
4968e0a
Compare
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.
Thanks @elia!
On the matter of private methods, I think we may want to make them public, but in this case having private methods may also be an acceptable exception. The API seems to make 100% sense to me. |
4968e0a
to
01b237f
Compare
01b237f
to
5305751
Compare
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.
@elia thank you! Looks good, I left a comment on a small improvement, let me know your opinion!
I discussed with Elia via chat about the improvement (replace the method |
Works for me, can we just add some documentation/example on how people should use this? |
The accepted values are "gt" or "gte" but the default value was set to the symbol for greater-than. It was never a problem because the HTML form will use the correct values for its dropdown select and the first value happens to be the intended default value.
5305751
to
069f333
Compare
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.
Looks good!
For what it's worth, the second commit contains the word "extendability", which should probably be "extensibility". The meaning is clear, so I don't care at all if you change it.
- Make operators extendable without reopening the method - Allow to overwrite/extend the total - Allow to overwrite/extend the threshold - Simplify #eligible? making it more readable - Migrate the OPERATORS constant to an extendible method - Fix the default preferred operator
Also support a generic message that can work with any operator.
069f333
to
3f1be03
Compare
Fixed, thanks! |
Thanks @elia ! |
Please use operators_map now. Ref solidusio#3431
Please use operators_map now. Ref solidusio#3431
Please use operators_map now. Ref solidusio#3431
Please use operators_map now. Ref solidusio#3431
Please use operators_map now. Ref solidusio#3431
Please use operators_map now. Ref solidusio#3431
Please use operators_map now. Ref solidusio#3431
Description
This change stems from the need to add the
:eq
/===
operator and to modify the total, beyond that need it should make the code more readable and linear.Checklist: