Column Filtering

I create a stock report in the administrator and everything still works, except that I can’t filter in the combined column.

I joined stock information using the following to capture my collection.

$collection = Mage::getModel('catalog/product')->getCollection()
                ->addAttributeToSelect('name')
                ->addAttributeToSelect('sku')
                ->addAttributeToSelect('price')
                ->setStoreId($storeId);
$collection->addFieldToFilter('type_id', 'simple');

// Add on the stock qty information
$collection->getSelect()->join( array('stock'=>'ccmg_cataloginventory_stock_item'), 'e.entity_id = stock.item_id', array('stock.qty'));

This causes it to display, but you cannot filter or sort the column. I assume that the parameters are not passed back to the connection. However, other columns can be sorted and filtered, and the corresponding data will be pushed back and displayed.

I searched, but most posts have been on the Magento forums since 2008, and I'm using 1.6! Any pointers would be great!

+5
source share
2 answers

_map, Varien_Data_Collection_Db, :

$this->_map['fields']['stock_qty'] = 'stock.qty';

[edit] @sh4dydud3_88, :

$collection->addFilterToMap('stock_qty', 'stock.qty');

stock_qty .

$collection->addFieldToFilter('stock_qty', array('gt', 10));

:

class Company_Mohe_Model_Resource_Im_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
protected function _construct()
{
    $this->_init('mohe/im');
}  


public function joinIhe()
{
    $this->getSelect()->join(array('ihe' => $this->getTable('mohe/ihe')),
                                  'main_table.mic_inst_id = ihe.im_id',
                                  array('ihe_name'=>'name', 'ihe_ifms_id'=>'ifms_id')); 
    //$this->_map['fields'] = array('ihe_name'=>'ihe.name', 'ihe_ifms_id'=>'ihe.ifms_id'); //incorrect method
    $this->addFilterToMap('ihe_name', 'ihe.name'); //correct method, see comment by @sh4dydud3_88                           
    return $this;
} 
} 
+12

$collection->getSelect()
    ->join( array('stock'=>'ccmg_cataloginventory_stock_item'), 'e.entity_id = stock.item_id', array('stock.qty'))
    ->order('stock.qty ASC');
0

All Articles