I have used a custom model where I am fetching value of <source_field> when I print an Invoice. Below is the code used in config.xml.

                <mymodule translate ="title">
                    <title>My Module Value</title>

I have created a Model file under MyModule/Model/Sales/Pdf/Mymodule.php and the DB filed name is mymodule_amount.

Below is my model file code


class Namespace_Mymodule_Model_Sales_Pdf_Mymodule extends Mage_Sales_Model_Order_Pdf_Total_Default

    public function getTotalsForDisplay()
        $mymoduleAmount =  $this->getMymoduleAmount();
        $label    =  'Some label';        
        $fontSize =  $this->getFontSize() ? $this->getFontSize() : 7;
        $total = array(
            'amount'    => '-'.$mymoduleAmount,
            'label'     => $label,
            'font_size' => $fontSize
        return array($total);


In the above code, $this->getMymoduleAmount(), returns null and can't fetch the value as defined in <source_field>.

Please Help.



To get the total from the source field you can simply call getAmount if your class extends Mage_Sales_Model_Order_Pdf_Total_Default which it appears to do.

 * Get Total amount from source
 * @return float
public function getAmount()
    return $this->getSource()->getDataUsingMethod($this->getSourceField());
| improve this answer | |
  • How do I call getAmount in above code ? Where do I need to perform the changes ? – Jordan Aug 18 '14 at 9:17
  • $amount = $this->getOrder()->formatPriceTxt($this->getAmount()); should get you the formatted price amount. This is taken directly from the original getTotalsForDisplay code – David Manners Aug 18 '14 at 9:19
  • why it does not work with my source field defined ? Or could you pls explain the code a bit – Jordan Aug 18 '14 at 9:25
  • Because either you do not have a function getMymoduleAmount or it does not call the original function. – David Manners Aug 18 '14 at 9:26
  • I agree that I don't have the getMymoduleAmount function. If necessary, where should I create it and how to fetch value from that function ? Moreover why can't I use the source_field value directly ? – Jordan Aug 18 '14 at 9:37

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.