Guest User

How to add user comments from OneStepCheckout extension to printing order pages in Magento

a guest
Jul 17th, 2010
314
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. ** How to add user comments from OneStepCheckout extension to printing order pages
  3. **   more info at: http://mandagreen.com/adding-customer-comments-invoice-pdf-magento/
  4. **
  5. ** 1. Place the function _insertOscComments as is, into the Abstract.php file
  6. ** 2. Add the function call to the end of insertTotals function
  7. */
  8.  
  9. // Will create a box with the user comments
  10. protected function _insertOscComments(&$page, $order) {
  11.    
  12.     $START_LINE1 = 145;
  13.     $START_LINE2 = $START_LINE1 * 2;
  14.     $START_LINE3 = $START_LINE1 * 3;
  15.    
  16.     $BOX_1LINE = 40;
  17.     $BOX_2LINES = 60;
  18.     $BOX_3LINES = 75;
  19.    
  20.     $commentTitle = Mage::helper('onestepcheckout')->__('Customer Comments');      
  21.     $commentMsg = Mage::helper('onestepcheckout')->__('No Comments Added'); //"Ingen kommentarer";
  22.     $commentMsgLine1 = '';
  23.     $commentMsgLine2 = '';
  24.     $commentMsgLine3 = '';
  25.    
  26.     if( !$order->getOnestepcheckoutCustomercomment() ) {
  27.         // by pass if no comment was added
  28.         // return;     
  29.     }
  30.     else {
  31.         $commentMsg = preg_replace('/\r\n/', ' ', $order->getOnestepcheckoutCustomercomment());
  32.     }      
  33.    
  34.     /* Box height */
  35.     $BOX_HEIGHT = $BOX_1LINE;      
  36.     if(strlen($commentMsg) > $START_LINE1 && strlen($commentMsg) <= $START_LINE2) $BOX_HEIGHT = $BOX_2LINES;
  37.     if(strlen($commentMsg) > $START_LINE2) $BOX_HEIGHT = $BOX_3LINES;
  38.    
  39.     /* Normal parameters */
  40.     $this->y -= 20;
  41.     $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
  42.     $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
  43.     $page->setLineWidth(0.5);
  44.     $page->drawRectangle(25, $this->y, 570, $this->y - 20);
  45.     $page->setFillColor(new Zend_Pdf_Color_Rgb(1, 1, 1));
  46.     $page->drawRectangle(25, $this->y - 20, 570, $this->y - $BOX_HEIGHT); // 1 line = 40, 2 lines = 60, 3 lines = 75
  47.     $page->setFillColor(new Zend_Pdf_Color_RGB(0.1, 0.1, 0.1));
  48.     $page->drawText($commentTitle, 35, $this->y - 13, 'UTF-8');
  49.    
  50.     /* divide comment up to 3 lines */
  51.     if(strlen($commentMsg) <= $START_LINE1) {
  52.         $commentMsgLine1 = $commentMsg;
  53.        
  54.         $page->drawText($commentMsgLine1, 33, $this->y - 33, 'UTF-8');
  55.         $this->y -= 50;
  56.     }
  57.     else if(strlen($commentMsg) > $START_LINE1 && strlen($commentMsg) <= $START_LINE2) {
  58.         $commentMsgLine1 = substr($commentMsg, 0, $START_LINE1);
  59.         $commentMsgLine2 = substr($commentMsg, $START_LINE1);
  60.        
  61.         $page->drawText($commentMsgLine1, 33, $this->y - 33, 'UTF-8');
  62.         $page->drawText($commentMsgLine2, 33, $this->y - 48, 'UTF-8');
  63.         $this->y -= 70;
  64.     }
  65.     else if(strlen($commentMsg) > $START_LINE2) {
  66.         $commentMsgLine1 = substr($commentMsg, 0, $START_LINE1);
  67.         $commentMsgLine2 = substr($commentMsg, $START_LINE1, $START_LINE1);
  68.         $commentMsgLine3 = substr($commentMsg, $START_LINE2);
  69.        
  70.         $page->drawText($commentMsgLine1, 33, $this->y - 33, 'UTF-8');
  71.         $page->drawText($commentMsgLine2, 33, $this->y - 48, 'UTF-8');
  72.         $page->drawText($commentMsgLine3, 33, $this->y - 63, 'UTF-8');
  73.         $this->y -= 95;
  74.     }
  75. }
  76.  
  77. /*
  78. **  At the end of insertTotals($page, $source) method you will see:
  79. */
  80.  
  81.     $page = $this->drawLineBlocks($page, array($lineBlock));
  82.         return $page;
  83.    
  84. /*
  85. **  Change that line into
  86. */ 
  87.  
  88.         $page = $this->drawLineBlocks($page, array($lineBlock));
  89.        
  90.     /* Add OneStepCheckout Customer Comments */
  91.     $this->_insertOscComments($page, $order);
  92.        
  93.         return $page;
RAW Paste Data