Magento invoice generation

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 /* $order is a valid Mage_Sales_Model_Order object */ $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

  /* Payment */ $paymentInfo = Mage::helper('payment')->getInfoBlock($order->getPayment()) ->setIsSecureMode(true) ->toPdf(); // $paymentInfo is an empty string when rendering a PDF externally, // and formatted as expected when rendering a PDF via the admin panel $payment = explode('{{pdf_row_separator}}', $paymentInfo); 

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.

+6
source share
2 answers

I hope this helps someone else. Sometimes, when you ask a detailed question, it makes you think more clearly. It was a very simple solution, without a clear error message indicating that the problem was!

Magento uses two folders for the adminhtml and frontend template files. By default for <file> there is only a .phtml file for the billing data auxiliary file. My script was run on the front-end without detecting this file and releasing an empty line.

In short, if your PDF invoices in Magento <= 1.6.1 do not have billing information when rendering on the interface, take this file:

app/design/adminhtml/default/default/template/paygate/info/pdf.phtml

Then copy / paste it into:

app/design/frontend/base/default/template/paygate/info/pdf.phtml (or, if you want, your own template directory)

In retrospect, I probably should use a background layout for my cron scripts.

Edit: Today I found out about the var / log / system.log file in Magento ... (Re-editing for clarity) The /var/log/system.log file clearly told me what the problem was, I just did not read it.

+2
source

I tried Mahdi.Montgomery's solution, but it never worked for me.

My problem is almost the same, but instead of not having billing information, I donโ€™t have a payment method. But my inner sensitivity is that the main reason is the same - the PDF template for the administrator and the interface is different, which is not very intuitive. It seems that I feel somehow wrong.

I saw this link from http://www.magentocommerce.com/boards/v/viewthread/463492/

Answering my own question, this is a Magento bug, see http://www.magentocommerce.com/boards/{path:viewforumโ–บ/viewthread/270256/#t397540

Fix:

In frontend / base / default / template / payment / info, create a pdf folder and copy all .phtml files into it.

Hope this helps someone.

0
source

Source: https://habr.com/ru/post/905785/


All Articles