Why are the payment methods not showing on my Sales > Orders grid?
I can get the column showing with the drop down list of payment options but the payment method values are not showing on the list of orders.
This is the query that produces the orders list:
SELECT `main_table`.*, `payment`.`method`
FROM
`sales_flat_order_grid` AS `main_table`
INNER JOIN `sales_flat_order_payment` AS `payment`
ON main_table.entity_id=payment.parent_id
The column I need to display the values for is called method
and returns the correct results, for example worldpay_cc
. The values are returned from the query but just aren't showing in the grid.
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->join(array('payment'=>'sales/order_payment'),'main_table.entity_id=payment.parent_id','method');
$collection->addProductData();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('method', array(
'header' => $this->__('Payment Method'),
'index' => 'method',
'type' => 'options',
'width' => '70px',
'options' => array(
'worldpay_cc' => 'Worldpay',
'cashondelivery' => 'Cash on Delivery',
'pay' => 'Pay',
'paypal_express' => 'Paypal Express',
)
));
return parent::_prepareColumns();
}
Any ideas?
My guess would be that you haven't mapped the payment methods correctly maybe:
Mage_Adminhtml_Block_Sales_Order_Grid
protected function _prepareColumns()
{
$this->addColumn('method', array(
'header' => $this->__('Payment Method'),
'index' => 'method',
'type' => 'options',
'width' => '70px',
'options' => array( // <--- The mapping, here
'worldpay_cc' => 'Worldpay',
'cashondelivery' => 'Cash on Delivery',
'pay' => 'Pay',
'paypal_express' => 'Paypal Express',
)
));
return parent::_prepareColumns();
}
I would change the above to:
protected function _prepareColumns()
{
$this->addColumn('method', array(
'header' => $this->__('Payment Method'),
'index' => 'method',
'type' => 'options',
'width' => '70px',
'options' => $this->getActivePaymentMethods()
));
return parent::_prepareColumns();
}
public function getActivePaymentMethods()
{
$payments = Mage::getSingleton('payment/config')->getActiveMethods();
$methods = array();
foreach ($payments as $paymentCode=>$paymentModel) {
$paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title');
$methods[$paymentCode] = $paymentTitle;
}
return $methods;
}
With reference to my comment, addProductData
is a custom function:
Mage_Sales_Model_Order_Grid_Collection
public function addProductData($attributesCodes)
{
foreach ($attributesCodes as $attributeCode) {
$attributeTableAlias = $attributeCode . '_table';
$attribute = Mage::getSingleton('eav/config')
->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
$this->getSelect()->join(
array($attributeTableAlias => $attribute->getBackendTable()),
"main_table.product_id = {$attributeTableAlias}.entity_id AND {$attributeTableAlias}.attribute_id={$attribute->getId()}",
array($attributeCode => 'value')
);
$this->_map['fields'][$attributeCode] = 'value';
}
return $this;
}