I am working on magento product collection query. My requirement to fetch products which are present in array of category.

Example: $all_selected_categories = array('15','35','48','75');

Above categories are from many seperate websites.

My query is:

$collection_check = Mage::getModel('catalog/product')   
                    ->addAttributeToFilter('status', 1);        
$collection_check->joinField('category_id','catalog/category_product', 'category_id', 'product_id = entity_id',null, 'left');     
$collection_check->addAttributeToFilter('category_id', array('in' =>array('finset' => $all_selected_categories)));

But i am getting error of already exists of id.


Please try using the following line


at the end.

| improve this answer | |


$collection_check->addAttributeToFilter('category_id', array('in' => array('finset' => $all_selected_categories)));


 $collection_check = Mage::getModel('catalog/product')
->addAttributeToSelect(array('entity_id','name','description','created_at','price','status','parent_id')) ->addAttributeToFilter('status', 1)->addAttributeToFilter('category_id', array('in' => $all_selected_categories));
| improve this answer | |
  • Not working giving same error – Mathew Oct 9 '15 at 10:38
  • update answer check it – Qaisar Satti Oct 9 '15 at 10:45

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.