1

In Magento PDF invoice the Payment Method is Showing as COD but the COD Charges is not appearing in PDF, how can i display COD Charges in PDF invoice.

in PDF invoice it will appear like this :

Subtotal: AED 672.00
Discount: -AED 20.00
Shipping & Handling: AED 20.00
Grand Total: AED 672.00

But in Actual Order

Subtotal: AED 672.00
Discount: -AED 20.00
COD Charges : AED 15.00
Shipping & Handling: AED 20.00
Grand Total: AED 687.00

enter image description here

1 Answer 1

1

I don't know how you add COD Charges in the order so I will write a code how to add COD Charges only in PDF Invoice in Magento core files. I highly recommend to transfer this code in the custom module that you are using.

in app/code/core/Mage/Sales/etc/config.xml -> in pdf/totals node add this:

        <codcharges translate="title">
            <title>COD Charges</title>
            <model>sales/order_pdf_total_codcharges</model>
            <font_size>7</font_size>
            <display_zero>0</display_zero>
            <sort_order>300</sort_order>
        </codcharges>

then create new file app/code/core/Mage/Sales/Model/Order/Pdf/Total/Codcharges.php with this content:

<?php
class Mage_Sales_Model_Order_Pdf_Total_Codcharges extends Mage_Sales_Model_Order_Pdf_Total_Default
{
    public function getTotalsForDisplay()
    {
        $price = 15; //or write a code to get it from where you store it for each order
        $amount = $this->getOrder()->formatPriceTxt($price);
        $label = Mage::helper('sales')->__($this->getTitle());
        $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
        $total = array(
            'amount'    => $amount,
            'label'     => $label,
            'font_size' => $fontSize
        );
        return array($total);
    }
}

For hints you can see app/code/core/Mage/Sales/Model/Order/Pdf/Total/Default.php.


To add it to the Grand Total of the Invoice please try with this:

in config.xml in sales/order_invoice/totals node add:

            <codcharges>
                <class>sales/order_invoice_total_codcharges</class>
                <after>subtotal,discount</after>
                <before>grand_total,tax</before>
            </codcharges>

Create new file app/code/core/Mage/Sales/Model/Order/Invoice/Total/Codcharges.php:

<?php
class Mage_Sales_Model_Order_Invoice_Total_Codcharges extends Mage_Sales_Model_Order_Invoice_Total_Abstract
{
    public function collect(Mage_Sales_Model_Order_Invoice $invoice)
    {
        $amount = 15; //or write a code to get it from where you store it for each order
        $invoice->setGrandTotal($invoice->getGrandTotal() + $amount);
        $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $amount);

        return $this;
    }
}
7
  • Thanks for your answer I highly recommend to transfer this code in the custom module that you are using. Can you explain this ?
    – Jijesh
    Dec 22, 2014 at 5:22
  • I suppose that you are using custom module/modification to add COD Charges to the order because as far as I know there is no such thing in Magento by default.
    – michael
    Dec 22, 2014 at 6:55
  • Its Working Fine, but the COD Charges is not adding to Grand Total, How can i do that ?
    – Jijesh
    Dec 22, 2014 at 8:31
  • I understand that you already did this and you are asking only for the PDF Invoice (this is the question). But if you didn't do it - you can search in google for "magento add new total to order" or "magento add fee to order" - there are a lot of examples.
    – michael
    Dec 22, 2014 at 16:15
  • If you mean to add it only to the Grand Total of the Invoice - please see again my answer (I added additional code).
    – michael
    Dec 22, 2014 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.