Creating credit memo does not change order grand total?
-
13-12-2019 - |
Question
I have added extra fee in the checkout page and save it to the database but when I go to credit memos the extra fee is shown in Credit memo totals but the grand total is not updated
This is my config.xml file
<blocks>
<adminhtml>
<rewrite>
<sales_order_creditmemo_totals>My_Module_Block_Adminhtml_Sales_Order_Creditmemo_Totals</sales_order_creditmemo_totals>
</rewrite>
</adminhtml>
</blocks>
Solution
Check this module on github by Adam Moss. I have used the creditmemoSaveBefore()
method in observer for the same solution.
(Use your extra charge fee variable at the place of $depositAmount
)
Code:
class Creare_Deposit_Model_Observer {
/* ... */
public function creditmemoSaveBefore(Varien_Event_Observer $observer)
{
$post_data = Mage::app()->getRequest()->getPost();
$creditmemo = $observer->getEvent()->getCreditmemo();
$deposit_amount = $post_data['creditmemo']['deposit_amount'];
if ($deposit_amount > 0)
{
$depositAmount = $creditmemo->getDepositAmount();
$baseDepositAmount = $creditmemo->getDepositAmount();
// Adjust Grand Total to reflect Deposit refund
$creditmemo->setGrandTotal($creditmemo->getGrandTotal()-($depositAmount-$deposit_amount));
$creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal()-($baseDepositAmount-$deposit_amount));
// Set Deposit Total to actual refund amount
$creditmemo->setDepositAmount($deposit_amount);
$creditmemo->setBaseDepositAmount($deposit_amount);
}
return $this;
}
/* ... */
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange