Magento add Gift Message to packing slip

I wanted to add gift messages to the PDF packing slip, for some reason this isn’t standard in Magento (you write a gift message that never goes to customer, makes sense)

To add the gift message you need to go to /app/code/core/Mage/Sales/Model/Order/Pdf/Shipment.php

You then need to add the following code, I added it after

Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_SHIPMENT_PUT_ORDER_ID, $order->getStoreId())
);

But it depends where you want to display it on the PDF

/* START Add Gift Message to Packing Slip */
$this->_drawHeader1($page);
$this->_setFontBold($style, 10);

$message = Mage::getModel(‘giftmessage/message’);
$gift_message_id = $order->getGiftMessageId();
if(!is_null($gift_message_id)) {

$message->load($gift_message_id);
$gift_sender = $message->getData(‘sender’);
$gift_recipient = $message->getData(‘recipient’);
$gift_message = $message->getData(‘message’);

$page->drawText(Mage::helper(‘sales’)->__(‘Message from:’), 35, $this->y, ‘UTF-8’);
$page->drawText(Mage::helper(‘sales’)->__($gift_sender), 120, $this->y, ‘UTF-8’);
$this->y -=15;
$page->drawText(Mage::helper(‘sales’)->__(‘Message to:’), 35, $this->y, ‘UTF-8’);
$page->drawText(Mage::helper(‘sales’)->__($gift_recipient), 120, $this->y, ‘UTF-8’);
$this->y -=15;
$page->drawText(Mage::helper(‘sales’)->__(‘Message:’), 35, $this->y, ‘UTF-8’);
$page->drawText(Mage::helper(‘sales’)->__($gift_message), 120, $this->y, ‘UTF-8’);
$this->y -=15;

while ($token != false) {
if ($y < 60) {
$pdf->pages[] = ($page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4));
$page->setStyle($style);
} else {
$page->drawText($token, 30, $this->y);
$this->y-=10;
}
$token = strtok(“\n”);
}
}
/* END Gift Message to Packing Slip */

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.