0
<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    Mage
 * @package     Mage_Sales
 * @copyright  Copyright (c) 2006-2017 X.commerce, Inc. and affiliates (http://www.magento.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

/**
 * Sales Order Invoice PDF model
 *
 * @category   Mage
 * @package    Mage_Sales
 * @author     Magento Core Team <core@magentocommerce.com>
 */
class Mage_Sales_Model_Order_Pdf_Invoice extends Mage_Sales_Model_Order_Pdf_Abstract
{
    /**
     * Draw header for item table
     *
     * @param Zend_Pdf_Page $page
     * @return void
     */
    protected function _drawHeader(Zend_Pdf_Page $page)
    {



/* Add table head */
        $this->_setFontRegular($page, 10);
        $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
        $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
        $page->setLineWidth(0.5);
        $page->drawRectangle(25, $this->y, 570, $this->y -15);
        $this->y -= 10;
        $page->setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0));

    //columns headers
    $lines[0][] = array(
        'text' => Mage::helper('sales')->__('Products'),
        'feed' => 35
    );

    $lines[0][] = array(
        'text'  => Mage::helper('sales')->__('SKU'),
        'feed'  => 290,
        'align' => 'right'
    );

    $lines[0][] = array(
        'text'  => Mage::helper('sales')->__('Qty'),
        'feed'  => 435,
        'align' => 'right'
    );

    $lines[0][] = array(
        'text'  => Mage::helper('sales')->__('Price'),
        'feed'  => 360,
        'align' => 'right'
    );

    $lines[0][] = array(
        'text'  => Mage::helper('sales')->__('Tax'),
        'feed'  => 495,
        'align' => 'right'
    );

    $lines[0][] = array(
        'text'  => Mage::helper('sales')->__('Subtotal'),
        'feed'  => 565,
        'align' => 'right'
    );
    $lines[0][] = array(
        'text'  => Mage::helper('sales')->__('Subtotal1'),
        'feed'  => 635,
        'align' => 'right'
    );

    $lineBlock = array(
        'lines'  => $lines,
        'height' => 5
    );

    $this->drawLineBlocks($page, array($lineBlock), array('table_header' => true));

    $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
    $this->y -= 20;
}

/**
 * Return PDF document
 *
 * @param  array $invoices
 * @return Zend_Pdf
 */
public function getPdf($invoices = array())
{
    $this->_beforeGetPdf();
    $this->_initRenderer('invoice');

    $pdf = new Zend_Pdf();
    $this->_setPdf($pdf);
    $style = new Zend_Pdf_Style();
    $this->_setFontBold($style, 10);

    foreach ($invoices as $invoice) {
        if ($invoice->getStoreId()) {
            Mage::app()->getLocale()->emulate($invoice->getStoreId());
            Mage::app()->setCurrentStore($invoice->getStoreId());
        }
        $page  = $this->newPage();
        $order = $invoice->getOrder();
        /* Add image */
        $this->insertLogo($page, $invoice->getStore());
        /* Add address */
        $this->insertAddress($page, $invoice->getStore());
        /* Add head */
        $this->insertOrder(
            $page,
            $order,
            Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order->getStoreId())
        );
        /* Add document text and number */
        $this->insertDocumentNumber(
            $page,
            Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId()
        );
        /* Add table */
        $this->_drawHeader($page);
        /* Add body */
        foreach ($invoice->getAllItems() as $item){
            if ($item->getOrderItem()->getParentItem()) {
                continue;
            }
            /* Draw item */
            $this->_drawItem($item, $page, $order);
            $page = end($pdf->pages);
        }
        /* Add totals */
        $this->insertTotals($page, $invoice);
        if ($invoice->getStoreId()) {
            Mage::app()->getLocale()->revert();
        }
    }
    /***************custom******************/

    $this->_setFontRegular($page, 10);
    $page->setFillColor(new Zend_Pdf_Color_RGB(1, 1, 1));
    $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
    $page->setLineWidth(0.5);
    $page->drawRectangle(25, $this->y, 570, $this->y -15);
    $this->y -= 10;
    $page->setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0));
    $page->drawText('Have a question? Our 9x7 customer service is here to help you on XXXXXX from 09:00 AM – 06:00 PM', 70, $this->y);

    /*echo $this->y."-";
    echo $page->getHeight();die;*/
    $this->_setFontRegular($page, 10);
    $page->setFillColor(new Zend_Pdf_Color_RGB(1, 1, 1));
    $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
    $page->setLineWidth(0.5);
    $page->drawRectangle(25, $this->y-50, 570, $this->y-10);
    $page->setFillColor(new Zend_Pdf_Color_RGB(0, 0, 0));
    $page->drawText('Disclaimer:-', 30, $this->y-20);
    $page->drawText('1. The goods sold as part of this shipment are intended for end user consumption and not for resale.', 30, $this->y-30);
    $page->drawText('2. This is a system generated invoice, no signature required.', 30, $this->y-40);
    /***********custom ends************************/
    $this->_afterGetPdf();
    return $pdf;
}

/**
 * Create new page and assign to PDF object
 *
 * @param  array $settings
 * @return Zend_Pdf_Page
 */
public function newPage(array $settings = array())
{
    /* Add new table head */
    $page = $this->_getPdf()->newPage(Zend_Pdf_Page::SIZE_A4);
    $this->_getPdf()->pages[] = $page;
    $this->y = 800;
    if (!empty($settings['table_header'])) {
        $this->_drawHeader($page);
    }
    return $page;
}
}

Changed file app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php

I have added custom code for append disclaimer in invoice pdf. It is working fine on localhost and disclaimer is added in pdf but its not working on server.Even when I deleted the Invoice.php on server nothing changes.Its generating pdf.How to debug it,Why its not calling the file on server.Please help,thanks in advance.

1

first of all, Magento has better ways of customization than editing the core files, and this could also be an issue on the server.

Have your verified that your file gets loaded and your function gets called? If there's a file in app/code/local/Mage/[...], this file will be used instead of your file that you placed inside the core. Also, if there's an override using the config.xml file of another module, your file will never get loaded.

I prefer to use this module: https://github.com/firegento/firegento-debug to see if a rewrite of a model is in place.

Other problems could come from an Opcache like APC (if you're using an old PHP version) or ZendOpCache. Look if one of them is active and clean it.

Also, check if Magento is compiled. If it is, it will use class files from includes/*. You have to re-compile it.

Anyway, your solution with editing the core will lead to problems in every situation I can imagine:, for example custom extensions that modify the PDF, updates and patches. So you should really make a module out of this.

  • Thanks a lot,I had wasted lot of hours in it. It was compilation. – Ajay Dhul Feb 27 '18 at 14:24

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.