Solution 1
Working with an existing invoice
To change an existing invoice status from paid
to pending
is actually quite simple despite all the complexity built around it.
To do this, pay no attention to the invoice status
but focus solely on the invoice state
. All you have to do is change the invoice state
to the new desired state and the status
gets updated as well.
Since the invoice has already been paid for, you probably want to reset the total_paid
and base_total_paid
fields of the particular order the invoice was for so you at some point later on mark it as paid.
This should do just that:
<?php
$incrementId = '100014637';
$invoiceModel = Mage::getModel('sales/order_invoice');
try {
$invoice = $invoiceModel->loadByIncrementId($incrementId);
$order = Mage::getModel('sales/order')->load((int)$invoice->getOrderId());
$order->setTotalPaid(0)
->setBaseTotalPaid(0)
->save();
$invoice->setState(1)
->save();
} catch (Exception $ex) {
var_dump($ex->getMessage()); die;
}
To later mark it as paid on shipping, all you need do is simply get the invoice and call the pay
method on it.
Solution 2
Working with a new invoice
In order to create a pending
invoice, the payment method you use for the order must allow you to do such.
For that you need to override the payment method model and add these membere:
protected $_canCapture = true; // sets state to open
protected $_canCapturePartial = true; // lets you invoice partially
For example if you want to do this for Check/money order or Cash On Delivery you need to override either app/code/core/Mage/Payment/Model/Method/Checkmo.php or app/code/core/Mage/Payment/Model/Method/Cashondelivery.php and add the above attribute.
After this when you create an invoice you will have an option near the save button to set the invoice status. To create a pending invoice select Not capture
as seen below.
If you want to mark it later as paid edit the invoice and between the buttons on to one called Capture
.
Since what you want to do is mark it as paid on shipping, all you need do is simply get the invoice and call the pay
method on it.
Hope it helps someone.
invoice[capture_case]
was missing in invoice create form. I have addedinvoice[capture_case]
in invoice form. Now there is no problem with creating invoice.