Tuesday 16 September 2014

Magento Add Payment Method to Admin invoice Grid

 protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass());
      
        $collection->join(array('payment'=>'sales/order_payment'),'main_table.order_id=parent_id',array('method','po_number'));
      
        $collection->getSelect()->joinLeft('sales_flat_order_address', 'main_table.order_id = sales_flat_order_address.parent_id',array('full_name'=>'CONCAT(sales_flat_order_address.firstname, " " , sales_flat_order_address.lastname)','full_address'=>'CONCAT(sales_flat_order_address.street, " ", sales_flat_order_address.city, sales_flat_order_address.postcode)','telephone','city','firstname','postcode','company','street','email' ) )->where("sales_flat_order_address.address_type =  'billing'");
      
      
          $collection->getSelect()->joinLeft('sales_flat_order', 'main_table.order_id=sales_flat_order.entity_id', array("shipping_desc"=>"shipping_description","weight"=>"weight","subtotal_incl_tax"=>"subtotal_incl_tax","base_subtotal_invoiced"=>"base_subtotal_invoiced","base_shipping_invoiced"=>"base_shipping_invoiced","base_tax_amount"=>"base_tax_amount"));
        
     
         $this->setCollection($collection);
         return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
        
    }
$payments = Mage::getModel('payment/config')->getAllMethods();
        $methods = array();
            foreach ($payments as $paymentCode=>$paymentModel)
            {
                $paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title');
                $methods[$paymentCode] = $paymentTitle;
            }
            $this->addColumnAfter('method', array(
                'header' => Mage::helper('sales')->__('Payment Method'),
                'index' => 'method',
                'filter_index' => 'method',
                'type'  => 'options',
                'width' => '1050px',
                'options' => $methods,
            ));

3 comments:

  1. Thanks a lot dude !!! you helped me to add a Customer ID in to the Invoice table which didnt work when i did joinLeft but doing this works.

    Thanks again!

    ReplyDelete
  2. I’ve been searching for some decent stuff on the subject and haven't had any luck up until this point, You just got a new biggest fan!..
    newizze.com

    ReplyDelete

Note: only a member of this blog may post a comment.