Magento:如何覆盖getOrder getGrandTotal,以便在将值传递给付款模块时更改金额

I'm trying to change the order grand total programmatically for purpose of allowing users to pay portion of the payment. I tried editing core file Mage_Payment_Model_Info method getMethodInstance

if (method_exists($instance,"getOrder")){
    $order = $instance->getOrder(); 
}else{

        $session = Mage::getSingleton('checkout/session');
        $order = Mage::getModel('sales/order');
        $order->loadByIncrementId($session->getLastRealOrderId());

}
$total=$order->getGrandTotal()/2;
$order->setGrandTotal($total);

I know this is not the best way, but was experimenting to find the best way . How to achieve this? I plan to put the changed in a custom module. so not going to keep changes in core files. thanks

I had to do something similar recently and there were some big problems, but first the good news.

  • The amount charged is based on invoices, invoice for the portion and the order's paid amount will increase appropriately.
  • An order may have many invoices.
  • You don't need to alter the grand total. Leave that intact as a record of what they need to pay.

However,

  • The order items each need to be marked as invoiced. When an order is half paid then you must work out which items are accounted for intelligently. If an order has one $10 item and one $100 item which are paid by the first $20?
  • An order cannot be overpaid. Thanks to a false assumption the difference between amount owed and amount paid (the "due") will not show negative numbers, this is a fallacy and makes it really hard to pay two pending orders at once.

One way that I didn't think of in time would be to have credit accounts for each customer. When a payment is less than the entire order add it to the account instead and leave the order unpaid for now. Allow arbitrary (pre)payments to the account. Once the account is great enough use it to pay the order, you might want to make a payment module for this bit.
Or it could work in reverse, pay all orders immediately and leave a negative balance in the credit account to be paid at a later date. I suspect this would be the least painful way of all.