How can i apply the new qty to refund items of refund object?
-

I want to change the refund qty for partial refund fails. If i update mannually in refund item that does not update order calculation and refund calculation even if collectTotals called.
-
@enamulislamjisan
Updating only theqtyon a refund item is not enough. ThecollectTotals()methods do not recalculate item amounts from the quantity—they only sum the values already stored on the refund items.Because of this, changing
refund_item.qtyalone leaves fields such astotal,base_total,tax_amount, anddiscount_amountunchanged, so the refund and order totals remain the same.Recommended approach
If you're modifying the refund quantity for a partial refund, update the quantity before creating the refund. The
RefundRepository::create()method calculates all refund item amounts, refund totals, order totals, and inventory adjustments based on the quantities provided in the input data.For example:
$data['refund']['items'][$orderItemId] = $newQty; $refund = $refundRepository->create($data);This ensures all related calculations are performed correctly.
If the refund has already been created
If you need to modify an existing refund, changing the
qtyalone is insufficient. You must also recalculate the refund item's monetary fields (such astotal,base_total,tax_amount, anddiscount_amount) based on the new quantity, then call the appropriatecollectTotals()methods to update the refund and order aggregates.Keep in mind that if the refund quantity changes after creation, you may also need to adjust inventory manually, as inventory updates are handled during refund creation and are not recalculated by
collectTotals().