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.

3

2 Answers 2

0

Please try using the following line

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

at the end.

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));
2
  • Not working giving same error
    – Mathew
    Oct 9, 2015 at 10:38
  • update answer check it Oct 9, 2015 at 10:45

Your Answer

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

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