Skip to content

Commit

Permalink
Bugfix for refund bundle items
Browse files Browse the repository at this point in the history
  • Loading branch information
eneiasramos committed Dec 26, 2023
1 parent 6bfb90e commit 423e7a7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/code/core/Mage/Sales/Model/Order/Creditmemo.php
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,11 @@ public function getFilteredCollectionItems($filter = null)
public function isLast()
{
foreach ($this->getAllItems() as $item) {
$orderItem = $item->getOrderItem();
if ($orderItem->isDummy()) {
continue;
}

if (!$item->isLast()) {
return false;
}
Expand Down
17 changes: 15 additions & 2 deletions app/code/core/Mage/Sales/Model/Order/Creditmemo/Total/Subtotal.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
$subtotalInclTax = 0;
$baseSubtotalInclTax = 0;

$order = $creditmemo->getOrder();

foreach ($creditmemo->getAllItems() as $item) {
if ($item->getOrderItem()->isDummy()) {
continue;
Expand All @@ -41,8 +43,19 @@ public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)

$subtotal += $item->getRowTotal();
$baseSubtotal += $item->getBaseRowTotal();
$subtotalInclTax += $item->getRowTotalInclTax();
$baseSubtotalInclTax += $item->getBaseRowTotalInclTax();
$subtotalInclTax += $item->getRowTotalInclTax() + $item->getWeeeTaxAppliedRowAmount();
$baseSubtotalInclTax += $item->getBaseRowTotalInclTax() + $item->getBaseWeeeTaxAppliedRowAmount();
}

$allowedSubtotal = $order->getSubtotal() - $order->getSubtotalRefunded();
$baseAllowedSubtotal = $order->getBaseSubtotal() - $order->getBaseSubtotalRefunded();

if ($creditmemo->isLast()) {
$subtotal = $allowedSubtotal;
$baseSubtotal = $baseAllowedSubtotal;
} else {
$subtotal = min($allowedSubtotal, $subtotal);
$baseSubtotal = min($baseAllowedSubtotal, $baseSubtotal);
}

$creditmemo->setSubtotal($subtotal);
Expand Down
4 changes: 4 additions & 0 deletions app/code/core/Mage/Sales/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,8 @@
</row_weight>
<row_total>
<to_quote_item>*</to_quote_item>
<to_invoice_item>*</to_invoice_item>
<to_cm_item>*</to_cm_item>
</row_total>
<applied_rule_ids>
<to_quote_item>*</to_quote_item>
Expand All @@ -797,6 +799,8 @@
</base_tax_amount>
<base_row_total>
<to_quote_item>*</to_quote_item>
<to_invoice_item>*</to_invoice_item>
<to_cm_item>*</to_cm_item>
</base_row_total>
<base_price>
<to_invoice_item>base_price</to_invoice_item>
Expand Down

0 comments on commit 423e7a7

Please sign in to comment.