3

I wanted to display only the product name on the shipment pdf. I assume I need to edit the below section from shipment.php and I tried $item->getName() but it didn't work

How can i do this ?

foreach ($shipment->getAllItems() as $item) {               
    if ($item->getOrderItem()->getParentItem()) {
        continue;
    }
    /* Draw item */
    $this->_drawItem($item,$page, $order);
1

You need to modify the following class:

app/code/core/Mage/Sales/Model/Order/Pdf/Items/Shipment/Default.php


/**
 * Draw item line
 */
public function draw()
{
    $item   = $this->getItem();
    $pdf    = $this->getPdf();
    $page   = $this->getPage();
    $lines  = array();

    // draw Product name
    $lines[0] = array(array(
        'text' => Mage::helper('core/string')->str_split($item->getName(), 60, true, true),
        'feed' => 100,
    ));

    // draw QTY
    $lines[0][] = array(
        'text'  => $item->getQty()*1,
        'feed'  => 35
    );

    // draw SKU
    $lines[0][] = array(
        'text'  => Mage::helper('core/string')->str_split($this->getSku($item), 25),
        'feed'  => 565,
        'align' => 'right'
    );

    // Custom options
    $options = $this->getItemOptions();
    if ($options) {
        foreach ($options as $option) {
            // draw options label
            $lines[][] = array(
                'text' => Mage::helper('core/string')->str_split(strip_tags($option['label']), 70, true, true),
                'font' => 'italic',
                'feed' => 110
            );

            // draw options value
            if ($option['value']) {
                $_printValue = isset($option['print_value'])
                    ? $option['print_value']
                    : strip_tags($option['value']);
                $values = explode(', ', $_printValue);
                foreach ($values as $value) {
                    $lines[][] = array(
                        'text' => Mage::helper('core/string')->str_split($value, 50, true, true),
                        'feed' => 115
                    );
                }
            }
        }
    }

    $lineBlock = array(
        'lines'  => $lines,
        'height' => 20
    );

    $page = $pdf->drawLineBlocks($page, array($lineBlock), array('table_header' => true));
    $this->setPage($page);
}

Note: Don't modify core file.

  • Hi Sohel thanks for your reply, where does the getAllItems() method comes from. foreach ($shipment->getAllItems() as $item) – raul Feb 23 at 12:56
  • Yes, that comes from app/code/core/Mage/Sales/Model/Order/Pdf/Shipment.php::getPdf – Sohel Rana Feb 23 at 15:36
  • Hello just one more question how to get the current order increment id on the shipment.php page – raul Feb 23 at 22:41
  • $order = $shipment->getOrder(); $order->getIncrementId(); – Sohel Rana Feb 24 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.