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

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');
}
  • Looks good but I get error - Call to a member function getGrandTotal() on a non-object – Jon Sep 20 '16 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 Sep 20 '16 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 Sep 20 '16 at 12:20
  • I needed to change $this->customtext($page); to customtext($page, $invoice); when calling the function – Jon Sep 21 '16 at 13:38

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.