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

Distribute over eligible line items #2582

Merged
merged 6 commits into from
Feb 28, 2018

Conversation

Sinetheta
Copy link
Contributor

@Sinetheta Sinetheta commented Feb 18, 2018

There's a surprising interaction between the distributed amount calculator and the product promotion rule. The entire discount amount is distributed among all of an order's line_items, but only adjustments on line_items that match the promotion rule are considered "actionable" and contribute towards the order promo total.

https://github.com/solidusio/solidus/blob/master/core/app/models/spree/promotion/actions/create_item_adjustments.rb#L32

This means that as you add products to your cart, your discount can actually go down, which I don't imagine is a behaviour anyone would want.

screen shot 2018-02-18 at 10 11 59 am

Here the total discount has dropped from the preferred amount of $10 to ($22.99 / $38.98) = $5.90 the portion of the discount which was distributed to the item on sale.

I think there's larger discussion to be had about line item adjustments, but for now I'd just like to fix this one calculator. If only "actionable" line items can receive an adjustment then we need to distribute the desired amount among only those line items.

screen shot 2018-02-18 at 10 41 00 am

The calculator works as intended, but the test could be more strict.
Since line_item level promotion adjustments are only applied to
elligible line_items, there's a surprising interaction between
the distributed amount calculator and the product promotion rule.

The calculator distributes the preffered amount among all of the
order's line_items but only discounts the order by the portion
which was applied to the line_item with the elligible product.
By only giving weight to line_items which are elligible for the
promotion, the entire preffered_amount will be distributed.
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 work, Kevin!

I ask myself why we don't call compute_line_item only on eligible line items anyway.

@adammathys
Copy link
Contributor

I don't believe this is the best way to fix this issue. Now that the handler is reliant on knowing about the promotion, there's little purpose for it being its own class. It is directly tied to the calculator and to only ever being used for promotions.

A better approach would be passing the handler the list of items and an amount to distribute. Then updating the the interface to query for the amount that should be applied to a specific item.

@tvdeyen
Copy link
Member

tvdeyen commented Feb 19, 2018

@adammathys I agree, but was hesitant to refuse the PR because of that. But on second thought we should think about a solution to only action on eligible items.

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just left a small comment, the rest makes sense to me, thanks @Sinetheta !

core/app/models/spree/distributed_amounts_handler.rb Outdated Show resolved Hide resolved
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.

None yet

5 participants