Skip to content

Commit

Permalink
Fix "ambiguous column" errors when filtering by original columns.
Browse files Browse the repository at this point in the history
  • Loading branch information
colinmollenhour committed Mar 6, 2012
1 parent f5580b9 commit fba1ce2
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion code/Block/Adminhtml/Sales/Order/Grid.php
Expand Up @@ -10,7 +10,12 @@ class Cm_OrderProducts_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_B
const XML_PATH_RENDER_COLUMN = 'sales/cmorderproducts/render';
const XML_PATH_FILTER_COLUMN = 'sales/cmorderproducts/filter';

// MUST override setCollection rather than _prepareCollection to get filtering and paging both working
/**
* MUST override setCollection rather than _prepareCollection to get filtering and paging both working
*
* @param Mage_Sales_Model_Mysql4_Order_Grid_Collection $collection
* @return
*/
public function setCollection($collection)
{
parent::setCollection($collection);
Expand All @@ -34,6 +39,13 @@ protected function _prepareColumns()
parent::_prepareColumns();
if( ! Mage::getStoreConfig(self::XML_PATH_RENDER_COLUMN) || $this->_isExport) return;

// Specify table to fix ambiguous column errors
foreach($this->getColumns() as $column) {
if($column->getIndex()) {
$column->setFilterIndex('`main_table`.'.$column->getIndex());
}
}

$this->addColumnAfter('skus', array(
'header' => Mage::helper('sales')->__('Products Ordered (%s)', Mage::getStoreConfig(self::XML_PATH_RENDER_COLUMN)),
'index' => 'skus',
Expand Down

0 comments on commit fba1ce2

Please sign in to comment.