Distribute over eligible line items #2582
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.