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);
  • can you add more code? if it is a custom collection use $collection->addFieldToFilter('category_id', array('in' => array('finset' => array($newArray)))); – Qaisar Satti Jul 15 '16 at 12:21
  • Yes updated with code. pls check – Saravanan DS Jul 15 '16 at 12:23
  • did you try this code $collection->addFieldToFilter('category_id', array('in' => array('finset' => array($newArray)))); – Qaisar Satti Jul 15 '16 at 12:25
  • yes. but no result. – Saravanan DS Jul 15 '16 at 12:26
  • try this one $collection->addFieldToFilter('category_id',array('in' => $newArray)); – Qaisar Satti Jul 15 '16 at 12:27
1

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

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

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.