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.10k
    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"?>
    <config>
      <modules>
        <Custom_Fee>
          <version>0.1.1</version>
        </Custom_Fee>
      </modules>
      <global>
     <pdf>
          <totals>
            <fee translate ="title">
              <title>ExtraFee</title>
              <source_field>BaseFeeAmount</source_field>
              <model>Custom_Fee_Model_Totalpdf</model>
              <amount_prefix>-</amount_prefix>
              <font_size>7</font_size>
              <display_zero>0</display_zero>
              <sort_order>650</sort_order>
            </fee>
          </totals>
        </pdf>
      </global> 
    </config>

    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.

     

    <?php
    
    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
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
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: