Display Attributes on Invoice or Packing Slip in Magento

Add this to Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php, replace ATTRNAME as appropriate.

public function draw()
    {
       ...
       $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $this->getSku($item), array('ATTRNAME'));
 
       if ($product) {
         $lines[0][] = array(
           'text'  => Mage::helper('core/string')->str_split($product->getData('ATTRNAME'), 15),
           'feed'  => 305
          );
       }

Then add this to Mage/Sales/Model/Order/Pdf/Invoice.php, replace ATTR_TITLE as appropriate and OFFSET with the left offset.

/* Add table head */
...
$page->drawText(Mage::helper('sales')->__('ATTR_TITLE'), OFFSET, $this->y, 'UTF-8');
if (!empty($settings['table_header'])) {
...
$page->drawText(Mage::helper('sales')->__('ATTR_TITLE'), OFFSET, $this->y, 'UTF-8');

There is no definitive solution as you need to change a few other details to limit column widths in other areas depending on where you are trying to put your values (ie. description is usually made narrower and forced to line-wrap).

Referenced from: http://www.magentocommerce.com/boards/viewthread/18142/P15/#t201627

This entry was posted in Magento and tagged , , , , , . Bookmark the permalink.

7 Responses to Display Attributes on Invoice or Packing Slip in Magento

  1. How would I add the customer’s email address to the PDF invoice?

    I noticed that if I add this code:
    $customer = Mage::getModel(‘customer/customer’)->load($order->getData(‘customer_id’));
    $email = $customer->getData(‘email’);
    $page->drawText($email, 35, 735, ‘UTF-8′);

    —- that it will add the customer’s email, but only if they have an account.

    How do I add the customer’s email to the PDF invoice if they checked out as a GUEST?

    thankx :D

    Reply


  2. Answered by own question:

    In Order/PDF/Abstract.php:

    After the code:

    foreach ($billingAddress as $value){
    if ($value!==”) {
    $page->drawText(strip_tags(ltrim($value)), 35, $this->y, ‘UTF-8′);
    $this->y -=10;
    }
    }

    I added this code:

    /* email goes here */
    $page->drawText(Mage::helper(‘sales’)->__(”).$order->getCustomerEmail(), 35, $this->y, ‘UTF-8′);

    Hope that helps anyone else.

    Reply


    • The code provided by Brian works perfect, but be careful about getting the punctuation right when you’re implementing it. When I just cop/pasted this, it used the wrong style of quote marks and broke it.

      You want to use:

      $page->drawText(Mage::helper('sales')->__('').$order->getCustomerEmail(), 35, $this->y, 'UTF-8');

      Reply


  3. I appreciate you posting this. I was able to successfully modify the packslips to include the manufacture cost field.

    Thanks,
    Tegan

    Reply


  4. So I get the title in my packing slip, but not the attributes. See: http://screencast.com/t/icfzThfW

    The attribute name is ‘afmetingen’.
    Here’s how I implement the code:

    Code 1: http://screencast.com/t/bWC6afUMKAu8
    Code 2: http://screencast.com/t/yDXxbxLsV99
    Code 3: http://screencast.com/t/Fr7B6rABEPSU
    Any tips how I solve this?

    Reply


  5. My bad. I made a mistake with the attribute name. It works now :-)

    Reply


    • Edwin,

      What was your mistake? Is this case sensitive? I cannot get the attribute field to populate, but I can the table header. Any help would be appreciated.

      My Code:

      Invoice.php

      if (!empty($settings['table_header'])) {
      $this->_setFontRegular($page);
      $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-15);
      $this->y -=10;

      $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4));
      $page->drawText(Mage::helper(‘sales’)->__(‘Product’), 35, $this->y, ‘UTF-8′);
      $page->drawText(Mage::helper(‘sales’)->__(‘SKU’), 255, $this->y, ‘UTF-8′);
      $page->drawText(Mage::helper(‘sales’)->__(‘Manufacturer’), 300, $this->y, ‘UTF-8′);
      $page->drawText(Mage::helper(‘sales’)->__(‘Price’), 380, $this->y, ‘UTF-8′);
      $page->drawText(Mage::helper(‘sales’)->__(‘Qty’), 430, $this->y, ‘UTF-8′);
      $page->drawText(Mage::helper(‘sales’)->__(‘Tax’), 480, $this->y, ‘UTF-8′);
      $page->drawText(Mage::helper(‘sales’)->__(‘Subtotal’), 535, $this->y, ‘UTF-8′);
      $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
      $this->y -=20;

      Reply


Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">