I added a new column to my sales order grid and it works perfectly. If I go the the recent orders grid from the customer view it doesn't work . I got an error message:
Column not found: 1054 Unknown column 'c.increment_id' in 'field list'
.
This is how I added the new column to my sales order grid:
public function beforeBlockToHtml(Varien_Event_Observer $observer)
{
$grid = $observer->getBlock();
/**
* Mage_Adminhtml_Block_Sales_Order_Grid
*/
if ($grid instanceof Mage_Adminhtml_Block_Sales_Order_Grid) {
$grid->addColumnAfter(
'customer_increment_id',
[
'header' => Mage::helper('ffm_codebin')->__('Customer Inc.'),
'index' => 'customer_increment_id',
'filter_index' => 'c.increment_id'
],
'entity_id'
);
}
}
public function beforeCollectionLoad(Varien_Event_Observer $observer)
{
$collection = $observer->getCollection();
if(!isset($collection)){
return;
}
if($collection instanceof Mage_Sales_Model_Resource_Order_Grid_Collection){
$collection->getSelect()->join(['c' => $collection->getTable('customer/entity')]
,'main_table.customer_id = c.entity_id', ['customer_increment_id' => 'increment_id']
);
}
}
These are the events which I used: core_block_abstract_to_html_before
and core_collection_abstract_load_before
. Please note that I do not want to add a new column for the recent orders grid just for the sales order grid. What should I change in my code ?
Thx
'customer/entity'
table. because the right now it is looking for column nameincrement_id
c.increment_id
they are not conflict but column name not correct. or did you create attribute for customer?