Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to change the Order total in PDF and Add our custom field in magento?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.04k
    Comment on it

    In magento sometimes we are required to apply our own custom fee charges to reflect them when we generate the PDF from invoice in admin panel. 

    Lets see how we can do it:

    1. Create a module with namespace as Custom and module as Fee.
    2. Then Create a file config.xml in etc folder in our module.

    Now, in our config.xml file at the path Custom/Fee/etc/config.xml write the below code in it :

    <?xml version="1.0"?>
            <fee translate ="title">

    In the above code we have defined our module with the version 0.1.1 and 
    then in global we have added new order totals in invoice PDF in admin, in which we have given in <source_field> tag BaseFeeAmount, which is the field name of our custom fee which we want to add on pdf total.

    Now, new model is created to show the new total in the pdf. Create a model with the name Totalpdf.
    and add the below code in it.


    class Custom_Fee_Model_Totalpdf extends Mage_Sales_Model_Order_Pdf_Total_Default {
     public function getTotalsForDisplay() {
       $amount = $this->getOrder()->formatPriceTxt($this->getAmount());
        if ($this->getAmountPrefix()) {
          $amount = $this->getAmountPrefix().$amount;
        $title = $this->_getSalesHelper()->__($this->getTitle());
        if ($this->getTitleSourceField()) {
          $label = $title . ' (' . $this->getTitleDescription() . '):';
        } else {
          $label = $title . ':';
        $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
        $total[0] = array(
          'amount'  => $amount,
          'label'   => $label,
          'font_size' => $fontSize
        return $total;

    Now checkout the print invoice in admin, a new total will be seen there.

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: