Skip to content
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

Merged
merged 4 commits into from
May 23, 2017

Conversation

graygilmore
Copy link
Contributor

@graygilmore graygilmore commented May 23, 2017

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:

Line Item Line Item Price Weighted Adjustment
Socks $5 -$1.5
Shoes $30 -$9
Slippers $15 -$4.5

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

screen shot 2017-05-23 at 2 14 37 pm

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.

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 :)

Copy link
Contributor

@jordan-brough jordan-brough left a 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.

core/app/models/spree/calculator/weighted_rate.rb Outdated Show resolved Hide resolved
core/app/models/spree/calculator/weighted_rate.rb Outdated Show resolved Hide resolved
core/app/models/spree/weighted_adjustments_handler.rb Outdated Show resolved Hide resolved
core/app/models/spree/weighted_adjustments_handler.rb Outdated Show resolved Hide resolved
core/app/models/spree/weighted_adjustments_handler.rb Outdated Show resolved Hide resolved
core/app/models/spree/weighted_adjustments_handler.rb Outdated Show resolved Hide resolved
@graygilmore
Copy link
Contributor Author

Great comments. Going to look at these now.

@jordan-brough
Copy link
Contributor

jordan-brough commented May 23, 2017

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.
@graygilmore graygilmore force-pushed the weight-rate-calculator branch from a0d97e7 to 1d3c062 Compare May 23, 2017 14:32
@graygilmore graygilmore changed the title Weighted Rate Calculator Distributed Amount Calculator May 23, 2017
Copy link
Contributor

@jordan-brough jordan-brough left a 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.
@graygilmore graygilmore force-pushed the weight-rate-calculator branch from 1d3c062 to 4b00354 Compare May 23, 2017 15:24
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.

Great stuff!

Missing the word `be`
@jordan-brough jordan-brough merged commit 5c54849 into solidusio:master May 23, 2017
@graygilmore graygilmore deleted the weight-rate-calculator branch June 15, 2017 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants