1

I have added a custom discount block when I print my Invoice PDF. It looks something like below

enter image description here

In my config.xml, I am using below code to add totals in PDF

<pdf>
            <totals>
                <mymodule translate ="title">
                    <title>Discount</title>
                    <source_field>mymodule_amount</source_field>
                    <font_size>7</font_size>
                    <display_zero>0</display_zero>
                    <sort_order>650</sort_order>
                </mymodule>
            </totals>
        </pdf>

How can I add a MINUS sign in front of discounted price ?

Thanks

1

So I assume the discount field comes from a custom module you wrote. It is possible to define a model under the pdf > totals > field section in your config.xml:

<pdf>
    <totals>
        <mymodule translate ="title">
            <title>Discount</title>
            <source_field>mymodule_amount</source_field>
            <model>mymodule/sales_pdf_discount</model>
            <font_size>7</font_size>
            <display_zero>0</display_zero>
            <sort_order>650</sort_order>
        </mymodule>
    </totals>
</pdf>

Of course you also need to have a model section in your config.xml.

Then you can implement the model under app/code/[code pool]/[namespace]/[module name]/Model/Sales/Pdf/Discount.php:

class Namespace_Mymodule_Model_Sales_Pdf_Discount extends Mage_Sales_Model_Order_Pdf_Total_Default
{

    public function getTotalsForDisplay()
    {
        // getAmount is defined in the parent class and should read
        // the value from the defined source_field in your config.xml
        $discount = $this->getAmount();
        $label = '- ' . Mage::helper('mymodule')->__('Discount');        
        $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
        $total = array(
            'amount'    => $discount,
            'label'     => $label,
            'font_size' => $fontSize
        );
        return array($total);
    }

}

In general, you can have a look at the implementation under app/code/core/Mage/Tax/Model/Sales/Order/Pdf/*.

| improve this answer | |
  • How do I add model section for pdf ? And is it necessary to make a new model for just a sign ? – Jordan Aug 14 '14 at 11:52
  • At least I do not think that there is any any other proper solution. The model is quite tiny, so this should not really be a problem. – Simon Aug 14 '14 at 12:01
  • I agree. I have included that minus sign elsewhere viz. order total and invoice blocks, but do you suggest specifying a minus sign in pdf as well ? – Jordan Aug 14 '14 at 12:07
  • If you show it elsewhere, it also makes sense in the PDF. I think it is also semantically correct to show it. By the way please accept answers if they solve your problems (not only this one, also look at your other questions). – Simon Aug 14 '14 at 12:11
  • it says PDF total model should extend Mage_Sales_Model_Order_Pdf_Total_Default – Jordan Aug 14 '14 at 12:35
1

The default discount total uses <amount_prefix>

           <discount translate="title">
                <title>Discount</title>
                <source_field>discount_amount</source_field>
                <amount_prefix>-</amount_prefix>
                <font_size>7</font_size>
                <display_zero>0</display_zero>
                <sort_order>200</sort_order>
            </discount>

provided your custom implementation does not circumvent it in its own version of getTotalsForDisplay(), you should be able to just use

     <pdf>
        <totals>
            <mymodule translate ="title">
                <title>Discount</title>
                <source_field>mymodule_amount</source_field>
                <amount_prefix>-</amount_prefix>
                <font_size>7</font_size>
                <display_zero>0</display_zero>
                <sort_order>650</sort_order>
            </mymodule>
        </totals>
    </pdf>
| improve this answer | |

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.