Reputation: 90
I'm trying to add a new column to Magento's sales order grid (Admin > Sales > Orders). I tried following the instructions located here: http://www.atwix.com/magento/customize-orders-grid/
I have copied the core file to the local folder so I can override it:
From: /public_html/wholesale/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
To: /public_html/wholesale/app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php
What's curious is that no matter what changes I make to EITHER file, nothing changes on the admin side. I can't even get a Mage::log() to work.
Once I get past that problem, I need to make sure that the changes I'm making are the right ones. I'm only trying to get the customer's company name. Here are the two pieces I've added:
protected function _prepareCollection()
{
// This line is from the original
$collection = Mage::getResourceModel($this->_getCollectionClass());
// This is the call where I try to bring in the extra field
// from another sales table
$collection->getSelect()->join(
'sales_flat_order_address',
'sales_flat_order.entity_id = sales_flat_order_address.parent_id',
array('company')
);
// These lines are also default
$this->setCollection($collection);
return parent::_prepareCollection();
}
In _prepareColumns():
$this->addColumn('company', array(
'header' => Mage::helper('sales')->__('Company'),
'index' => 'billing_company',
));
FYI, I'm using Magento 1.7.0.2
Upvotes: 0
Views: 3098
Reputation: 1587
Try this:
protected function _prepareCollection()
{
// This line is from the original
$collection = Mage::getResourceModel($this->_getCollectionClass());
// Join billing 'company' field from sales_flat_order_address table
$collection->getSelect()->join(
array('addressTable' => 'sales_flat_order_address'),
'main_table.entity_id = addressTable.parent_id AND addressTable.address_type = "billing"',
array('billing_company'=>'company')
);
// These lines are also default
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function filterBillingCompany($collection, $column) {
$val = (string)trim($column->getFilter()->getValue());
if ($val != "") {
$collection->getSelect()->where("addressTable.company LIKE '%{$val}%'");
}
return $this;
}
In _prepareColumns():
$this->addColumn('company', array(
'header' => Mage::helper('sales')->__('Company'),
'index' => 'billing_company',
'filter_condition_callback' => array($this, 'filterBillingCompany'),
));
Upvotes: 0