Where are the PDF invoices totals pulled from? I see that it is an array in abstract.php, but where does the original files come from?
1 Answer
It helps to take a look at how Magento implements it - most totals are added in the sales module in /app/code/core/Mage/Sales/etc/config.xml
For example the subtotal is defined here
<config>
<global>
<!-- SNIP -->
<sales>
<!-- SNIP -->
<quote>
<totals>
<subtotal>
<class>sales/quote_address_total_subtotal</class>
<after>nominal</after>
<before>grand_total</before>
</subtotal>
</totals>
</quote>
</sales>
</global>
</config>
and for the pdf here
<config>
<global>
<!-- SNIP -->
<pdf>
<!-- SNIP -->
<totals>
<subtotal translate="title">
<title>Subtotal</title>
<source_field>subtotal</source_field>
<font_size>7</font_size>
<display_zero>1</display_zero>
<sort_order>100</sort_order>
</subtotal>
</totals>
</pdf>
</global>
</config>
Use the above configuration in your own module's config.xml file as a start, Adjust subtotal = your total code. Further places to look into
/app/code/core/Mage/Sales/Model/Quote/Address
/app/code/core/Mage/Sales/Model/Order/Pdf
-
Hey, ok that makes sense. But I need to add two more informations for the totals. I know how to pull that informations from the order itself (price of the product with discount Incl, and Excl tax), but where to register that informations to be displayed in PDF invoices, what file? Where does totals array from Abstract.php comes from? Jul 1, 2013 at 21:10
-
You mean this $totals = Mage::getConfig()->getNode('global/pdf/totals')->asArray();? This is populated by all nodes in your configuration under global/pdf/totals so if you add any anything under it it will be included for you. Jul 1, 2013 at 21:12
-
In terms of where to add this: In your own modules config.xml file. Jul 1, 2013 at 21:13
-
Yep, got that. I need to add two stuffs there. One is Product price with discount (Excl tax), and the other one is Product price Product price with discount (Incl tax). Is that possible? So basically, One is: $subtotal = $item->getRowTotal() + $item->getTaxAmount() + $item->getHiddenTaxAmount() - $item->getDiscountAmount(); and Two is $subtotal = $item->getRowTotal() - $item->getDiscountAmount(); Jul 1, 2013 at 21:23
-
I think we are talking about different things. The totals to me are what is displayed after the individual items are listed. If you want to add a new column for each item you would need to take a look at overwriting /app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php with most of the interesting parts coming from the Abstract.php one folder level up. Jul 1, 2013 at 23:02