1

I am using magento 1.9 version. I am having custom collection which consists category ids. I tried to get the collection based on the category ids. I followed this link. I tried with this code too.

$collection->addAttributeToFilter('category_id', array('in' => array('finset' => array($newArray))));

but returns the empty collection. How to solve this.

Updates:

$collection = Mage::getModel('custommodule/custommodule')->getCollection()->addFieldToFilter('is_active',1);    
            $cat_ids = array();         
            $prod_ids = array();
            $result = array();
            $cat_ids = $collection->getColumnValues('category_id');
            $prod_ids = $product->getCategoryIds();
            $result = array_intersect($prod_ids, $cat_ids);
            $collection->addAttributeToFilter('category_id',array('finset'=>$result));
            echo '<pre>';
        print_r($collection);
19
  • can you add more code? if it is a custom collection use $collection->addFieldToFilter('category_id', array('in' => array('finset' => array($newArray)))); Jul 15, 2016 at 12:21
  • Yes updated with code. pls check Jul 15, 2016 at 12:23
  • did you try this code $collection->addFieldToFilter('category_id', array('in' => array('finset' => array($newArray)))); Jul 15, 2016 at 12:25
  • yes. but no result. Jul 15, 2016 at 12:26
  • try this one $collection->addFieldToFilter('category_id',array('in' => $newArray)); Jul 15, 2016 at 12:27

1 Answer 1

1

It seems you have already pass array($newArray), so use below code

  $collection->addAttributeToFilter('category_id', array('in' => array('finset' => $newArray)));
3
  • No luck. Returns the Same empty collection. Jul 15, 2016 at 12:16
  • have you tried $collection->addAttributeToFilter(‘category_id’,array(‘finset’=>$newArray)); ? Jul 15, 2016 at 12:18
  • yes. but same empty result. Jul 15, 2016 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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