2

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?

2

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? – Josip Gvozdić Jul 1 '13 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. – Kristof at Fooman Jul 1 '13 at 21:12
  • In terms of where to add this: In your own modules config.xml file. – Kristof at Fooman Jul 1 '13 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(); – Josip Gvozdić Jul 1 '13 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. – Kristof at Fooman Jul 1 '13 at 23:02

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.