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?
1 Answers
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;
}

- 1,704
- 1
- 12
- 23
-
Thank you for this very helpful answer. This overwrite existing field with subtotal, delivery rate, grand total - this I want to keep. I need additional field with grand total. Plz help! – Tim Sajt Oct 09 '12 at 07:45
-
You need Grand Total to be displayed twice? – CCBlackburn Oct 10 '12 at 22:14
-
Not only twice but four times. – Tim Sajt Oct 11 '12 at 22:28
-
ok, so I would set a local variable with the value of the Grand Total and then display it where you need to – CCBlackburn Oct 11 '12 at 23:05
-
Can I please for example, how to do this. – Tim Sajt Oct 11 '12 at 23:22