You need to extend the order grid (assuming that it is already familiar to you).
in the extended php file app/code/local/Yournamespace/Yourmodule/Block/Adminhtml/.../Grid.php
class Yournamespace_Yourmodule_Block_..._Grid extends Mage_Adminhtml_Block_Sales_Order_Grid{
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass())
->join(array('soa' => 'sales/order_address'), 'soa.parent_id=main_table.entity_id and soa.address_type = "billing"', array('full_address'=>'CONCAT(soa.firstname, " " , soa.lastname, ",<br/>", soa.street, ",<br/>", soa.city, ",<br/>", soa.region, ",<br/>", soa.postcode)' ), null,'left')
->join(array('soas' => 'sales/order_address'), 'soas.parent_id=main_table.entity_id and soas.address_type = "shipping"', array('full_address_ship'=>'CONCAT(soas.firstname, " " , soas.lastname, ",<br/>", soas.street, ",<br/>", soas.city, ",<br/>", soas.region, ",<br/>", soas.postcode)' ), null,'left');
$this->setCollection($collection);
return parent::_prepareCollection();
}
...
then inside protected function _prepareColumns()
method replace the following code
$this->addColumn('billing_name', array(
'header' => Mage::helper('sales')->__('Bill to Name'),
'index' => 'billing_name',
));
$this->addColumn('shipping_name', array(
'header' => Mage::helper('sales')->__('Ship to Name'),
'index' => 'shipping_name',
));
with
$this->addColumn('full_address', array(
'header'=> Mage::helper('sales')->__('Billing Address'),
'width' => '80px',
'type' => 'text',
'index' => 'full_address',
));
$this->addColumn('full_address_ship', array(
'header'=> Mage::helper('sales')->__('Shipping Address'),
'width' => '80px',
'type' => 'text',
'index' => 'full_address_ship',
));
You're done!
The other easy and recommended way would be using event and observer:
in your module config.xml
under config tag...
<config>
...
<adminhtml>
...
<events>
<sales_order_grid_collection_load_before>
<observers>
<vendor>
<type>singleton</type>
<class>yourmodule/adminhtml_observer</class>
<method>filterOrderCollection</method>
</vendor>
</observers>
</sales_order_grid_collection_load_before>
<core_block_abstract_prepare_layout_after>
<observers>
<vendor>
<type>singleton</type>
<class>yourmodule/adminhtml_observer</class>
<method>saleOrderLayout</method>
</vendor>
</observers>
</core_block_abstract_prepare_layout_after>
in app/code/local/Yournamespace/Yourmodule/Model/Adminhtml/Observer.php
<?php
class Yournamespace_Yourmodule_Model_Adminhtml_Observer{
public function filterOrderCollection($observer){
$collection = $observer->getEvent()->getOrderGridCollection();
$collection->join(array('soa' => 'sales/order_address'), 'soa.parent_id=main_table.entity_id and soa.address_type = "billing"', array('full_address'=>'CONCAT(soa.firstname, " " , soa.lastname, ",<br/>", soa.street, ",<br/>", soa.city, ",<br/>", soa.region, ",<br/>", soa.postcode)' ), null,'left');
$collection->join(array('soas' => 'sales/order_address'), 'soas.parent_id=main_table.entity_id and soas.address_type = "shipping"', array('full_address_ship'=>'CONCAT(soas.firstname, " " , soas.lastname, ",<br/>", soas.street, ",<br/>", soas.city, ",<br/>", soas.region, ",<br/>", soas.postcode)' ), null,'left');
}
public function saleOrderLayout($evt){
$tabBlock = $evt->getBlock();
if($tabBlock instanceof Mage_Adminhtml_Block_Sales_Order_Grid){
$tabBlock->addColumnAfter('full_address', array(
'header'=> Mage::helper('sales')->__('Billing Address'),
'width' => '80px',
'type' => 'text',
'index' => 'full_address',
), 'created_at');
$tabBlock->addColumnAfter('full_address_ship', array(
'header'=> Mage::helper('sales')->__('Shipping Address'),
'width' => '80px',
'type' => 'text',
'index' => 'full_address_ship',
), 'full_address');
}
}
}
Try replacing the line
$collection->addAttributeToSelect('manage_stock');
with
$collection->joinField('manage_stock',
'cataloginventory/stock_item',
'manage_stock',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left');
Your _prepareColumns function should look like this
protected function _prepareColumns(){
$this->addColumn('manage_stock', array(
'header'=> Mage::helper('catalog')->__('Manage Stock'),
'index' => 'manage_stock',
'type' => 'options',
'options' => array (
'0' => Mage::helper('core')->__('No'),
'1' => Mage::helper('core')->__('Yes'),
)
));
return parent::_prepareColumns();
}
Best Answer
I ended up resolving this by changing the event I was observing to
adminhtml_block_html_before
and then adding a little fancy finagling to re-sort the columns and allow for proper filtering. The old event was occuring before the default columns were being set up which is why they couldn't be removed.Here is the updated method with the new lines added below
$block->removeColumn('status');
Thanks goes out to this nifty GridControl extension which helped make the solution more obvious.