Sometimes you need to add custom order totals to your Magento store. For exmple you may have added new attribute ‘total_surcharge
‘ as custom order total attribute. This new order total will be visible in admin sales order view and invoice view generally. But when you generate the PDF from invoice, the new order total is not visible there.
We need to perform following simple steps in our module to add order total in invoice PDF:
1. Open your modules config.xml
and add following lines under global
node:
<config> [...] <global> [...] <!-- Add new order totals in invoice PDF in admin --> <pdf> <totals> <total_surcharge translate ="title"> <title>Assistance Fee</title> <source_field>total_surcharge</source_field> <!-- Source field is the code of your custom total attribute --> <model>shipmeorders/sales_pdf_assistancefee</model> <!-- This is the new model that we will create --> <amount_prefix>-</amount_prefix> <!-- If you need to place any sign before total --> <font_size>7</font_size> <display_zero>0</display_zero> <sort_order>650</sort_order> </total_surcharge> </totals> </pdf> </global> </config>
2. Create the new model for showing the new total in PDF:
<?php // app/code/local/Company/Mytotal/Model/Sales/Pdf/Surcharge.php class Company_Mytotal_Model_Sales_Pdf_Surcharge extends Mage_Sales_Model_Order_Pdf_Total_Default { public function getTotalsForDisplay() { // getAmount will automatically get the value of your new total // its value id defined source_field in your config.xml $amount = $this->getAmount(); $label = Mage::helper('mytotal')->__('Surchage').':'; $fontSize = $this->getFontSize() ? $this->getFontSize() : 7; $total = array( 'amount' => Mage::helper('core')->currency($amount, true, false), 'label' => $label, 'font_size' => $fontSize ); return array($total); } }
Now try to print invoice in admin, you should see the new order total there.
Not working
Please check if you have created the necessary file at proper location.
having problems in adding warranty in invoice ? how to fix that..
Hi Arvind
i am absolutely stuck with this problem:
I get no totals on the emailed invoice PDF. It is driving me grazy. There are totals on every needed place in the admin but not on the PDf that is send. What am i doing wrong. I checked every setting in admin, changed language, set back the mage version to 1.9.2.4 and back (its 1.9.3 again now) but no effort at all..
So before i jump from a bridge…. help!
Kind regards
John
How can we implement same technique to print bar code for any given reference number in shipping label?