-
-
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
Distribute over eligible line items #2582
Conversation
The calculator works as intended, but the test could be more strict.
d3dd747
to
7a1ab08
Compare
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.
7a1ab08
to
5e2b124
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 work, Kevin!
I ask myself why we don't call compute_line_item
only on eligible line items anyway.
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. |
@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. |
634a55b
to
16e2d48
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.
Just left a small comment, the rest makes sense to me, thanks @Sinetheta !
16e2d48
to
ea26427
Compare
ea26427
to
7b837d5
Compare
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.
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.