0

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')   
                    ->getCollection()       
                    ->addAttributeToSelect(array('entity_id','name','description','created_at','price','status','parent_id'))
                    ->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.

0

Please try using the following line

$collection_check->getSelect()->group('e.entity_id');

at the end.

| improve this answer | |
0

change

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

to

 $collection_check = Mage::getModel('catalog/product')
->getCollection()
->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.