2

I have problem with pdf invoice in Magento. I want to customize pdf invoice, that I used it for delivery. So I need one field with grand total price (only grand total). How can I get this grand total price?

Nate
  • 30,286
  • 23
  • 113
  • 184
Tim Sajt
  • 117
  • 5
  • 11

1 Answers1

2

The way Magento displays the totals in the PDF is pretty much the same way it does it within the shopping cart and checkout; it retrieves an array of the totals, displaying them as it iterates through them.

From what I understand, you only want to show the Grand Total in the Invoice PDF?

The code that handles the totals can be found in /app/code/core/Mage/Sales/Order/Pdf/Abstract.php in a function called insertTotals.

As it's in the Abstract.php file, the code will be used for invoices, credit memos etc, so you would have to not only override the /app/code/core/Mage/Sales/Order/Pdf/Invoice.php file by copying it to /app/code/local/Mage/Sales/Order/Pdf/Invoice.php (don't muck with the core!), but you would also have to override the insertTotals function and only display the Grand Total data:

public function insertTotals($page, $source){
    $order = $source->getOrder();
    $totals = $this->_getTotalsList($source);
    $lineBlock = array(
        'lines'  => array(),
        'height' => 15
    );


    foreach ($totals as $total) {
        $total->setOrder($order)
            ->setSource($source);

        // only allow Grand Total to be displayed
        if ($total->getSourceField() != 'grand_total')
        {
            continue;
        }

        if ($total->canDisplay()) {
            foreach ($total->getTotalsForDisplay() as $totalData) {
                $lineBlock['lines'][] = array(
                    array(
                        'text'      => $totalData['label'],
                        'feed'      => 475,
                        'align'     => 'right',
                        'font_size' => $totalData['font_size'],
                        'font'      => 'bold'
                    ),
                    array(
                        'text'      => $totalData['amount'],
                        'feed'      => 565,
                        'align'     => 'right',
                        'font_size' => $totalData['font_size'],
                        'font'      => 'bold'
                    ),
                );
            }
        }
    }

    $page = $this->drawLineBlocks($page, array($lineBlock));
    return $page;
}
CCBlackburn
  • 1,704
  • 1
  • 12
  • 23