-
-
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
Distributed Amount Calculator #1949
Distributed Amount Calculator #1949
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.
Looks good to me. I have a suggestion for the name of the calculator, but you can ignore me if you don't like it :)
backend/app/views/spree/admin/promotions/calculators/weighted_rate/_fields.html.erb
Show resolved
Hide resolved
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.
Looking great to me so far! I left a few minor comments.
backend/app/views/spree/admin/promotions/actions/_create_item_adjustments.html.erb
Outdated
Show resolved
Hide resolved
Great comments. Going to look at these now. |
You should add a screenshot of what the admin UI looks like for this calculator :) Best one I've seen I think. Edit: Oops, either you added it after I looked or I missed it at first. Either way: Great! |
This removes the need for specifying `partial` and `locals` keys as well as bringing the line length down.
We'll be introducing a new calculator for promotions that will allow order-level promotion values to be applied through line item adjustments. This class keeps some of the more complicated logic out of the calculator as it has to reach up to the order and calculate values on multiple line items.
a0d97e7
to
1d3c062
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 great!
This calculator allows us to use order level promotions ("Save $50 on your order") and spread that $50 over all of the line items. This calculator shoots logic off to another class to handle the calculations. Each line item needs to call out to the DistributedAmountsHandler separately which is annoying but each line item needs to be aware of the order as a whole. The calculator spreads the discount amount among each of the line items relative to their price. This means that more expensive items will receive a greater share of the discount.
1d3c062
to
4b00354
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.
Great stuff!
This allows admins to create order level promotions that get applied through line item adjustments. For example "Save $50 off your order" and we spread the $50 through line item adjustments.
Example
If you had a $15 promotion that you wanted to spread over three line items with differing prices:
Notes
This will help move us in the direction of removing order-level adjustments as discussed here: #1913
This may even allow us to deprecate a flat rate order-level adjustment if we wanted to move in that direction.
Admin Screenshot