0

I am using a function to show custom information on an invoice: (app/code/core/Mage/Sales/Model/Order/Pdf/invoice.php)

public function customtext($page)
{    
    $page->drawText(Mage::helper('sales')->__('custom text '), 35, $this->y, 'UTF-8');
}

Added at end of invoice.php, and $this->customtext($page); added to end of public function getPdf($invoices = array()) above $this->_afterGetPdf();

But I want to include in my custom text the value of 20% of my invoice Grand Total. How is this done?

1 Answer 1

1

if you can pass yo your function the invoice object you are displaying you can do it like this:

public function customtext($page, $invoice)
{    
    $price = $invoice->getGrandTotal() * 20 /100;
    $order = $invoice->getOrder();
    $page->drawText(Mage::helper('sales')->__($order->formatPriceTxt($price)), 35, $this->y, 'UTF-8');
}
4
  • Looks good but I get error - Call to a member function getGrandTotal() on a non-object
    – Jon
    Commented Sep 20, 2016 at 11:53
  • also getting errors - Call to a member function getOrder() on a non-object & Call to a member function formatPriceTxt() on a non-object. I added more specific details to my coding in the above queston
    – Jon
    Commented Sep 20, 2016 at 12:04
  • that's because $invoice is not an object in your case. I explained that this works only if you can pass the invoice parameter to your method
    – Marius
    Commented Sep 20, 2016 at 12:20
  • I needed to change $this->customtext($page); to customtext($page, $invoice); when calling the function
    – Jon
    Commented Sep 21, 2016 at 13:38

Your Answer

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

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