I think this an interesting topic. At the end of the day, no matter how initFromOrder
is being called, it is still necessary to add a new payment method to a reorder
or editorder
. It is really important to distinguish the difference between the payment data on the quote and on the order objects. It is the order object that ultimately executes place()
which fires the $payment->place()
function, which on an Order is type:
Mage_Sales_Model_Order_Payment
while on a quote it is type:
Mage_Sales_Model_Quote_Payment
So basically this funky looking function is just preping the Mage_Sales_Model_Quote_Payment
payment object so the order can ultimately meet the data requirements to place()
on the actual order object.
Keep in mind what is happening here:
$this->getQuote()->getPayment()->addData($order->getPayment()->getData());
The call to get payment data from the order is adding data to the quote payment. take a look at the difference between sales_flat_order_payment
and sales_flat_quote_payment
tables in the database. also note that the important table is sales_payment_transaction
.
This method initFromOrder
is used in two places,
1) the EditController,
2) the CreateController.
Magento has been migrating to Service Classes for most of the final high level functions, such as place order. this is where the real magic happens.
Mage_Sales_Model_Service_Quote::submitOrder
$order->setPayment($this->_convertor->paymentToOrderPayment($quote->getPayment()));
In the Edit Controller context, it is important to remember that Magento isn't actually allowing you to edit an order, it is canceling the order and making a new one leveraging data from the existing order. I've heard a lot of complaints about how this works on the back-end, but remember that Magento is a platform, and often the more specific they make the process, the more work each company using Magento has to fit their particular needs. So while I personally don't find this implementation 'great', it does offer a lot of room for custom business process on the back-end (with custom implementation required).
In the reorder
context, you're basically just duplicating the required data so Magento will be able to place the order. some of that has to be simulated since the OnePage process isn't being followed that same as on the front-end.
There is certainly a lot of 'assumption' in the way a re-order operates. I think many of the larger ecommerce stores running Magento tend to have integrated Payment Profile IDs or other mechanisms for being able to re-bill a customer.