Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ** How to add user comments from OneStepCheckout extension to printing order pages
- ** more info at: http://mandagreen.com/adding-customer-comments-invoice-pdf-magento/
- **
- ** 1. Place the function _insertOscComments as is, into the Abstract.php file
- ** 2. Add the function call to the end of insertTotals function
- */
- // Will create a box with the user comments
- protected function _insertOscComments(&$page, $order) {
- $START_LINE1 = 145;
- $START_LINE2 = $START_LINE1 * 2;
- $START_LINE3 = $START_LINE1 * 3;
- $BOX_1LINE = 40;
- $BOX_2LINES = 60;
- $BOX_3LINES = 75;
- $commentTitle = Mage::helper('onestepcheckout')->__('Customer Comments');
- $commentMsg = Mage::helper('onestepcheckout')->__('No Comments Added'); //"Ingen kommentarer";
- $commentMsgLine1 = '';
- $commentMsgLine2 = '';
- $commentMsgLine3 = '';
- if( !$order->getOnestepcheckoutCustomercomment() ) {
- // by pass if no comment was added
- // return;
- }
- else {
- $commentMsg = preg_replace('/\r\n/', ' ', $order->getOnestepcheckoutCustomercomment());
- }
- /* Box height */
- $BOX_HEIGHT = $BOX_1LINE;
- if(strlen($commentMsg) > $START_LINE1 && strlen($commentMsg) <= $START_LINE2) $BOX_HEIGHT = $BOX_2LINES;
- if(strlen($commentMsg) > $START_LINE2) $BOX_HEIGHT = $BOX_3LINES;
- /* Normal parameters */
- $this->y -= 20;
- $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
- $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
- $page->setLineWidth(0.5);
- $page->drawRectangle(25, $this->y, 570, $this->y - 20);
- $page->setFillColor(new Zend_Pdf_Color_Rgb(1, 1, 1));
- $page->drawRectangle(25, $this->y - 20, 570, $this->y - $BOX_HEIGHT); // 1 line = 40, 2 lines = 60, 3 lines = 75
- $page->setFillColor(new Zend_Pdf_Color_RGB(0.1, 0.1, 0.1));
- $page->drawText($commentTitle, 35, $this->y - 13, 'UTF-8');
- /* divide comment up to 3 lines */
- if(strlen($commentMsg) <= $START_LINE1) {
- $commentMsgLine1 = $commentMsg;
- $page->drawText($commentMsgLine1, 33, $this->y - 33, 'UTF-8');
- $this->y -= 50;
- }
- else if(strlen($commentMsg) > $START_LINE1 && strlen($commentMsg) <= $START_LINE2) {
- $commentMsgLine1 = substr($commentMsg, 0, $START_LINE1);
- $commentMsgLine2 = substr($commentMsg, $START_LINE1);
- $page->drawText($commentMsgLine1, 33, $this->y - 33, 'UTF-8');
- $page->drawText($commentMsgLine2, 33, $this->y - 48, 'UTF-8');
- $this->y -= 70;
- }
- else if(strlen($commentMsg) > $START_LINE2) {
- $commentMsgLine1 = substr($commentMsg, 0, $START_LINE1);
- $commentMsgLine2 = substr($commentMsg, $START_LINE1, $START_LINE1);
- $commentMsgLine3 = substr($commentMsg, $START_LINE2);
- $page->drawText($commentMsgLine1, 33, $this->y - 33, 'UTF-8');
- $page->drawText($commentMsgLine2, 33, $this->y - 48, 'UTF-8');
- $page->drawText($commentMsgLine3, 33, $this->y - 63, 'UTF-8');
- $this->y -= 95;
- }
- }
- /*
- ** At the end of insertTotals($page, $source) method you will see:
- */
- $page = $this->drawLineBlocks($page, array($lineBlock));
- return $page;
- /*
- ** Change that line into
- */
- $page = $this->drawLineBlocks($page, array($lineBlock));
- /* Add OneStepCheckout Customer Comments */
- $this->_insertOscComments($page, $order);
- return $page;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement