Fix DivisionByZeroError in creditmemo tax for zero base shipping amount #40467
+3
−2
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.
Description
The
collect()method inMagento\Sales\Model\Order\Creditmemo\Total\Taxhas a partial guard at line 137 that checks$orderShippingAmount > 0before dividing at line 139, but line 140 divides by$baseOrderShippingAmountwithout any zero-check.When an order has free shipping (
base_shipping_amount = 0), this causes aDivisionByZeroErrorat line 140:This is inconsistent with line 109 in the same method, which correctly guards
$baseOrderShippingAmountbefore dividing:Steps to reproduce
shipping_amount = 0,base_shipping_amount = 0)CreditmemoFactory::createByOrder()DivisionByZeroErroris thrown atTax.php:140In production, this is triggered by the Stripe webhook retry cron (
stripe_webhook_events_retry) when it attempts to cancel/refund an order with free shipping that has an existing invoice.Expected result
Credit memo is created without error. When shipping amounts are zero, the shipping tax proportion block is skipped entirely (no shipping tax to apportion).
Actual result
This error repeats on every cron cycle, blocking webhook retry processing.
Fix
Add
$baseOrderShippingAmount > 0to the existing guard clause at line 137, so both divisors ($orderShippingAmountat line 139 and$baseOrderShippingAmountat line 140) are protected.Related
The invoice path (line 109) already has the correct guard. This fix makes the non-invoice path consistent.