I need to merge two or more categories products and filter the common products from the collection.


Here's one way of doing it.

First, get the products ids from one category:

$productCollection1 = Mage::getResourceModel('catalog/product_collection')

Then get the products ids from the second category:

$productCollection2 = Mage::getResourceModel('catalog/product_collection')

Then you can intersect the two arrays of product ids to be sure you get the product ids that are available in both categories:

$finalProductIds = array_intersect($productCollection1, $productCollection2); 

Finally, if you need to get every detail about those products you can create a new collection based on the final array:

$finalProductCollection = Mage::getResourceModel('catalog/product_collection')
                          ->addAttributeToFilter('entity_id', array('in' => $finalProductIds));

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.