Monday, 28 October 2013

Add gift options in invoice pdf in Magento

for Add gift message to Magento’s PDF packingslip you have to modified invoice.php file in (\app\code\local\Mage\Sales\Model\Order\Pdf\Invoice.php)
it is a core file ao you have to move this file in local directory
 then find getPdf($invoices = array()) function in it

before   $this->_afterGetPdf();  this line add below code in it.

/*    Draw gift options*/
                $message = Mage::getModel('giftmessage/message');
                   $oid= $item->getOrderItemId();
                  $sales =  Mage::getModel('sales/order_item')->load($oid);
           
        $gift_message_id = $sales->getGiftMessageId();
        if(!is_null($gift_message_id)) {
              $message->load((int)$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:'), 55, $this->y, 'UTF-8');
              $page->drawText(Mage::helper('sales')->__($gift_sender), 120, $this->y, 'UTF-8');
             $this->y -=10;
              $page->drawText(Mage::helper('sales')->__('Message to:'), 55, $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:'), 55, $this->y, 'UTF-8');
              $page->drawText(Mage::helper('sales')->__($gift_message), 120, $this->y, 'UTF-8');
             
             // $gift_message = wordwrap($gift_message, 140, "\n", false);
              /*$token = strtok($gift_message, "\n");
              $y = 740;
              while ($token != false) {
              if ($y < 60) {
              $pdf->pages[] = ($page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4));
              $page->setStyle($style);
              }
              else {
              $page->drawText($token, 40, $this->y);
              $this->y-=10;
              }
              $token = strtok("\n");
              }*/

            }
                  /*    Draw gift options end*/

No comments:

Post a Comment