title: Fatal error: Call to a member function getPdf() on a non-object in controllers\Mage\Adminhtml\Sales\OrderController.php
body: <p>I am getting this following error in a module am developing to print custom invoice/pdf. The code is working upto the controller part, but when it tries to call the model an error is occurring there.</p>
  
  <p>I am not looking to overwrite the core model, as it is intended that old invoice should work as it is, and the new mass action warehouse order print should generate new type of PDF.
  Please help with following code, am stuck with no clues!</p>
  
  <pre><code>Fatal error: Call to a member function getPdf() on a non-object in C:\wamp\www\Goku\app\code\local\Goku\Ordersexporter\controllers\Mage\Adminhtml\Sales\OrderController.php on line 332
  </code></pre>
  
  <p>Structure of module</p>
  
  <pre><code>app-
    |-code
      |-local
          |-Goku
              |-Ordersexporter
                  |-Block
                  |   |-Mage
                  |       |-Adminhtml
                  |           |-Sales
                  |               |-Order
                  |                   |-Grid.php
                  |-controllers
                  |   |-Mage
                  |       |-Adminhtml
                  |           |-Sales
                  |               |-OrderController.php
                  |-etc
                  |   |-config.xml
                  |-Model
                      |-Order
                          |-Pdf
                              |-Invoice.php
  </code></pre>
  
  <p>1) grid.php</p>
  
  <pre><code>class Goku_Ordersexporter_Block_Mage_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
  {
      public function __construct()
      {
          parent::__construct();
      }
  
      protected function _prepareMassaction()
      {
  
          $this-&gt;getMassactionBlock()-&gt;addItem('Goku_warehouseOrderPrint', array(
              'label' =&gt; Mage::helper('sales')-&gt;__('Warehouse Order Sheet'),
              'url' =&gt; $this-&gt;getUrl('*/sales_order/Goku_warehouseOrderPrint'),
          ));
  
          parent::_prepareMassaction();
          return $this;
      }
  }
  </code></pre>
  
  <p>2) OrderController.php</p>
  
  <pre><code>$defController = Mage::getBaseDir()
      . DS . 'app' . DS . 'code' . DS . 'core'
      . DS . 'Mage' . DS . 'Adminhtml' . DS . 'controllers'
      . DS . 'Sales' . DS . 'OrderController.php';
  
  require_once $defController;
  
  class Goku_Ordersexporter_Mage_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController
  {
      public function Goku_warehouseOrderPrintAction()
      {
          $orderIds = $this-&gt;getRequest()-&gt;getPost('order_ids');
          $flag = false;
          if (!empty($orderIds)) {
              foreach ($orderIds as $orderId) {
                  $invoices = Mage::getResourceModel('sales/order_invoice_collection')
                      -&gt;setOrderFilter($orderId)
                      -&gt;load();
                  if ($invoices-&gt;getSize() &gt; 0) {
                      $flag = true;
                      if (!isset($pdf)) {
                          $pdf = Mage::getModel('Goku_Ordersexporter/order_pdf_invoice')-&gt;getPdf($invoices);
                      } else {
                          $pages = Mage::getModel('Goku_Ordersexporter/order_pdf_invoice')-&gt;getPdf($invoices);
                          $pdf-&gt;pages = array_merge($pdf-&gt;pages, $pages-&gt;pages);
                      }
                  }
              }
              if ($flag) {
                  return $this-&gt;_prepareDownloadResponse(
                      'invoice' . Mage::getSingleton('core/date')-&gt;date('Y-m-d_H-i-s') . '.pdf', $pdf-&gt;render(),
                      'application/pdf'
                  );
              } else {
                  $this-&gt;_getSession()-&gt;addError($this-&gt;__('There are no printable documents related to selected orders.'));
                  $this-&gt;_redirect('*/*/');
              }
          }
          $this-&gt;_redirect('*/*/');
      }
  }
  </code></pre>
  
  <p>3) config.xml</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;config&gt;
      &lt;modules&gt;
          &lt;Goku_Ordersexporter&gt;
              &lt;version&gt;1.0.0.0&lt;/version&gt;
          &lt;/Goku_Ordersexporter&gt;
      &lt;/modules&gt;
  
      &lt;global&gt;
          &lt;blocks&gt;
              &lt;adminhtml&gt;
                  &lt;rewrite&gt;
                      &lt;sales_order_grid&gt;Goku_Ordersexporter_Block_Mage_Adminhtml_Sales_Order_Grid&lt;/sales_order_grid&gt;
                  &lt;/rewrite&gt;
              &lt;/adminhtml&gt;
          &lt;/blocks&gt;
          &lt;models&gt;
              &lt;Goku_Ordersexporter&gt;
                  &lt;class&gt;Goku_Ordersexporter_Model&lt;/class&gt;
              &lt;/Goku_Ordersexporter&gt;
          &lt;/models&gt;
      &lt;/global&gt;
  
      &lt;admin&gt;
          &lt;routers&gt;
              &lt;adminhtml&gt;
                  &lt;args&gt;
                      &lt;modules&gt;
                          &lt;Goku_Ordersexporter before="Mage_Adminhtml"&gt;Goku_Ordersexporter_Mage_Adminhtml&lt;/Goku_Ordersexporter&gt;
                      &lt;/modules&gt;
                  &lt;/args&gt;
              &lt;/adminhtml&gt;
          &lt;/routers&gt;
      &lt;/admin&gt;
  
  &lt;/config&gt;
  </code></pre>
  
  <p>4) Invoice.php</p>
  
  <pre><code>class Goku_Ordersexporter_Mage_Sales_Model_Order_Pdf_Invoice extends Mage_Sales_Model_Order_Pdf_Invoice
  {
      public function getPdf($invoices = array())
      {
          $this-&gt;_beforeGetPdf();
          $this-&gt;_initRenderer('invoice');
  
          $pdf = new Zend_Pdf();
          $this-&gt;_setPdf($pdf);
          $style = new Zend_Pdf_Style();
          $this-&gt;_setFontBold($style, 10);
  
          foreach ($invoices as $invoice) {
              if ($invoice-&gt;getStoreId()) {
                  Mage::app()-&gt;getLocale()-&gt;emulate($invoice-&gt;getStoreId());
                  Mage::app()-&gt;setCurrentStore($invoice-&gt;getStoreId());
              }
              $page  = $this-&gt;newPage();
              $order = $invoice-&gt;getOrder();
              /* Add image */
              $this-&gt;insertLogo($page, $invoice-&gt;getStore());
              /* Add address */
              $this-&gt;insertAddress($page, $invoice-&gt;getStore());
              /* Add head */
              $this-&gt;insertOrder(
                  $page,
                  $order,
                  Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order-&gt;getStoreId())
              );
              /* Add document text and number */
              $this-&gt;insertDocumentNumber(
                  $page,
                  Mage::helper('sales')-&gt;__('Invoice # ') . $invoice-&gt;getIncrementId()
              );
              /* Add table */
              $this-&gt;_drawHeader($page);
              /* Add body */
              foreach ($invoice-&gt;getAllItems() as $item){
                  if ($item-&gt;getOrderItem()-&gt;getParentItem()) {
                      continue;
                  }
                  /* Draw item */
                  $this-&gt;_drawItem($item, $page, $order);
                  $page = end($pdf-&gt;pages);
              }
              /* Add totals */
              $this-&gt;insertTotals($page, $invoice);
              if ($invoice-&gt;getStoreId()) {
                  Mage::app()-&gt;getLocale()-&gt;revert();
              }
          }
          $this-&gt;_afterGetPdf();
          return $pdf;
      }
  
      public function newPage(array $settings = array())
      {
          /* Add new table head */
          $page = $this-&gt;_getPdf()-&gt;newPage(Zend_Pdf_Page::SIZE_A4);
          $this-&gt;_getPdf()-&gt;pages[] = $page;
          $this-&gt;y = 800;
          if (!empty($settings['table_header'])) {
              $this-&gt;_drawHeader($page);
          }
          return $page;
      }
  }
  </code></pre>