0

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();

        $newnote->_initNote();
        $var = $newnote->$_note;

        $vars = serialize($var);

        $this->insertDocumentNumber(
            $page,
            Mage::helper('sales')->__('Invoice # ') . $vars . $invoice->getIncrementId()
        );

How would I insert that into the PDF?

5
  • I don't know the plugin, but I assume there's a very interesting part that includes an order-object where $noteId is defined. :) Commented Nov 9, 2014 at 15:06
  • Yes there is I added that into the question above. How would I insert that into the pdf though?
    – Haru
    Commented Nov 9, 2014 at 15:10
  • What version of Magento are you using this on? Commented Nov 9, 2014 at 17:29
  • Instead of delivery_note_id I think it should be ship_note_id see github.com/drewhunter/ShipNote/blob/master/src/app/code/… Commented Nov 9, 2014 at 22:24
  • It actually was delivery_note_id.
    – Haru
    Commented Nov 11, 2014 at 19:35

2 Answers 2

1

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.
}
3
  • 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.
    – Haru
    Commented Nov 11, 2014 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.
    – Haru
    Commented Nov 11, 2014 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
    Commented Nov 11, 2014 at 13:42
0

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.

        $this->insertNote(
        $page,
        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 and acknowledge you have read our privacy policy.

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