I'm trying to add a custom note to Magento's invoice PDF documents. I'm using the Deliverynote plugin.

I am trying to add this piece of code to the invoice.php code but I'm not getting any results.

$noteId = Mage::registry('current_invoice')->getOrder()->getData('delivery_note_id'); 

$this->_note = Mage::getModel('deliverynote/note')->load($noteId)->getNote();

Here is the Github location https://github.com/drewhunter/ShipNote

I also tried doing this.

        $newnote = new Dh_Deliverynote_Block_Adminhtml_Sales_Order_Note();

        $var = $newnote->$_note;

        $vars = serialize($var);

            Mage::helper('sales')->__('Invoice # ') . $vars . $invoice->getIncrementId()

How would I insert that into the PDF?


You weren't that far off, I think.

I'm going to assume you're editing Mage_Sales_Model_Order_Pdf_Invoice.

In this model there's a variable $invoice, that contains all the invoice relevant data. It also has a relation to the order object, which you can retrieve using $invoice->getOrder().

That module you're using adds a relation to the order but you don't need it. Instead, we just load up the note itself using Mage::getModel('shipnote/note')->loadByOrder($invoice->getOrder()); which then has a magic getNote() method that will retrieve the actual note.

$shipnote = Mage::getModel('shipnote/note')->loadByOrder($invoice->getOrder());
if ($shipnote) { 
    $shipnote->getNote();  // use this wherever you want it to go.
  • This looks good. Shouldn't it be deliverynote/note? I still cannot get it to work though. It just gives me a blank page when I try to print the invoice. It's because of the first line of code. – Ninja Fist Nov 11 '14 at 2:58
  • The culprit is the loadByOrder bit. If I just do a regular load on a random number I can get the note. I wonder why loadByOrder is failing. – Ninja Fist Nov 11 '14 at 3:31
  • You can try using ->loadByOrderId($invoice->getOrderId()), see if that works. As to your earlier comment, the config.xml defines the model alias as shipnote, not deliverynote.. The above should work if you use shipnote/note, either with loadByOrder or loadByOrderId. Mind you, the ship_note_id attribute needs to be in the Order object, so if you adjusted that attribute in any way it wont work, you'll need to adjust the Model as well. – Rian Nov 11 '14 at 13:42

So what actually ended up working was this. It might have worked from the original $order variable in invoice.php but I am leaving it as is since it is working.

       $order3 = Mage::getModel('sales/order')->loadByIncrementId($order->getIncrementId());

       $shipNoteId = $order3->getData('delivery_note_id');

       $note = Mage::getModel('deliverynote/note')->load($shipNoteId)->getData('note');

Then in adding it into the invoice pdf I created a insertNote function.

        Mage::helper('sales')->__('USPS INSTRUCTIONS: ') . $note

I also made a video showing how to do this in Magento. http://youtu.be/bjZ31AlmN2I

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.