Solving Magento: Order has Invoice but ‘Total due’ > 0
If you’re facing an issue where your Magento order has been successfully invoiced and paid via iDEAL, yet the ‘Total due’ field remains greater than zero, preventing order completion, then this guide will help resolve it.
Understanding the Problem
The core issue lies in a potential bug within your iDEAL module. Despite the payment being processed successfully and an invoice generated, the total due amount isn’t being updated to reflect the paid status of the order.
Step-by-Step Solution
Verifying Order Status
First, confirm that the order is indeed invoiced by checking if order->getInvoiceCollection()->count() > 0. This ensures the invoice exists in the database before proceeding with any updates.
if ($order->getInvoiceCollection()->count() > 0) {
// Proceed to update
}
Fetching the Invoice ID
To interact with the existing invoice, fetch its ID:
$invoice_id = $order->getInvoiceCollection()->getFirstItem()->getId();
Updating Total Due Amount
Now, you need to modify the total due amount for this particular order. You can do this directly in your database or via Magento’s API.
Database Update: Execute a raw SQL query to update the sales_order_grid table where entity_id = $order->getId():
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$sql = "UPDATE sales_order_grid SET total_due=0 WHERE entity_id = {$order->getId()}";
$write->query($sql);
API Update: Alternatively, use Magento’s API to update the order:
$service_url = Mage::getUrl('adminhtml/sales_order/massUpdate');
$post_data = array(
'form_key' => Mage::getSingleton('core/session')->getFormKey(),
'order_ids' => array($order->getId()),
'update' => array('total_due' => 0)
);
Post this data to $service_url using curl.
Reindexing the Order Grid
After updating, reindex the order grid for the changes to take effect:
Mage::getSingleton('core/index_factory')->reindex(array('sales_order_grid'));
Conclusion
Resolving this issue involves a combination of database updates and API calls. By fetching the invoice ID and then modifying the total due amount, you can effectively force the order to be considered complete.
Remember, while this solution focuses on Magento 1.5.0.1, the principles remain applicable across versions. Always ensure you have proper backups before performing direct database modifications.
If you’re looking for more advanced solutions or need assistance with your e-commerce platform, feel free to explore our Magento development services at Laravel Companyâwe specialize in delivering robust, secure, and scalable Magento solutions tailored to meet your business needs.