Fix refund total ignoring order-level custom totals (e.g. payment discounts...)#2
Open
norgeindian wants to merge 1 commit into
Open
Fix refund total ignoring order-level custom totals (e.g. payment discounts...)#2norgeindian wants to merge 1 commit into
norgeindian wants to merge 1 commit into
Conversation
…counts)
RefundCalculator computed the refund by summing per-item row_total minus
item-level discount_amount. This missed any order-level adjustment stored
outside item fields — e.g. a payment-method discount (Fooman Surcharge
"Vorkassenrabatt") that is recorded as a custom total and reduces
grand_total without distributing to item discount_amount.
For such orders the calculator produced a total higher than grand_total,
causing the post-condition guard to throw a LogicException and rolling
back the entire withdrawal submission. The JS sidebar preview also
displayed the inflated amount.
Fix: after computing the item-based total, derive the order-level gap as
gap = grand_total - (sum(row_total - discount_amount) + sum(tax) + shipping + shipping_tax)
and distribute it proportionally to the fraction of the order's item value
being returned (ratio = itemsSubtotal / orderItemsBase). A full return
produces ratio 1.0 and always yields grand_total; a partial return gets a
fair proportional share. The gap is zero for standard orders, so there is
no behavioural change for orders without custom totals.
The same computation is added to form.phtml (passed to JS as
orderItemsBase + orderLevelGap) and withdrawal-summary.js so the live
sidebar preview stays in sync with the server calculation.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
RefundCalculator computed the refund by summing per-item row_total minus item-level discount_amount. This missed any order-level adjustment stored outside item fields — e.g. a payment-method discount (Fooman Surcharge) that is recorded as a custom total and reduces grand_total without distributing to item discount_amount.
For such orders the calculator produced a total higher than grand_total, causing the post-condition guard to throw a LogicException and rolling back the entire withdrawal submission. The JS sidebar preview also displayed the inflated amount.
Fix: after computing the item-based total, derive the order-level gap as
gap = grand_total - (sum(row_total - discount_amount) + sum(tax) + shipping + shipping_tax)and distribute it proportionally to the fraction of the order's item value being returned (
ratio = itemsSubtotal / orderItemsBase). A full return produces ratio 1.0 and always yields grand_total; a partial return gets a fair proportional share. The gap is zero for standard orders, so there is no behavioural change for orders without custom totals.The same computation is added to form.phtml (passed to JS as orderItemsBase + orderLevelGap) and withdrawal-summary.js so the live sidebar preview stays in sync with the server calculation.