0

i am trying to filter grid by category without adding category column, is there a way by which we can do this custom filter to grid.

below is what i did

function prepareCollection()
{
$catIdArray = getRequest()->getParam('cat_id');
//i.e  $catIdArray = array(26, 27, 17);

$collection = Mage::getModel('catalog/product')->getCollection(); 

$collection->joinField(
    'category_id',
    'catalog/category_product',
    'category_id',
    'product_id=entity_id',
    null,
    'left'
)
->addAttributeToFilter( 
    'category_id',
    array('in' => $catIdArray)
)
->addAttributeToSelect('*');
$this->setCollection($collection);

Here filter is working fine, but pagination doesn't work in this case. please suggest me what am i doing wrong????

1

Try this:

$this->joinTable(
    'catalog/category_product', // table to join
    'product_id=entity_id', // ON statement, flat table first!
    array(), // don't add any columns
    array('in' => $categoryIds) // additional WHERE
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.