I am trying to check new orders in Magento, and if they exist, send the invoice in PDF format to the site administrators. Everything is fine except for PDF.
If you try to create PDF invoices externally, the payment PDF file does not have all the payment information. Creating an invoice is pretty straight forward, but finding the reason for the lack of payment information was impossible for me. Here is what I learned.
My code to create the actual PDF invoice is below. This is the same code used in the standard pdfinvoicesAction by default to create PDF files for the admin admin server ( app/code/core/Mage/Adminhtml/controllers/Sales/OrderController.php:459 ).
cron/Invoice.php
<?php $invoices = $order->getInvoiceCollection(); $pdfInvoice = Mage::getModel('sales/order_pdf_invoice'); $pdf = $pdfInvoice->getPdf($invoices); $pdfFile = $pdf->render(); ?>
This creates a valid PDF file containing all order information minus billing. Isolating the reason for this, I found that in the next (default) file, the payment information order is an empty line - when I receive an invoice through the magento back-end, it returns a formatted line containing all the payment information.
app/core/Mage/Sales/Model/Order/Pdf/Abstract.php:221
$paymentInfo = Mage::helper('payment')->getInfoBlock($order->getPayment()) ->setIsSecureMode(true) ->toPdf();
So what's going on. I have no idea how or why. A real kicker? In my cron script job, if I run the following:
die(print_r($order->getPayment()->toArray()));
All information about the payment is.
I requested this on the Magento Developer Forum with no luck. I really hope someone can help shed some light on this issue as I have exhausted my debugging efforts. Thank you very much.
Edit: it just turned out that while Mage::helper('payment')->getInfoBlock($order->getPayment())->setIsSecureMode(true)->toHtml() returns correctly formatted HTML. ->toPdf nothing.