I want to get product ids of a specific category and product ids not in other categories only in a specific category.
For example,
category ids = 3, 4, 10 and product ids = 10, 12, 14 and category id 3 belong to product id 10 and category id 4 belong to product ids 10, 12, 14 and category id 10 belong to product id 14.
When I filter on category id = 4, it returns product ids 10, 12 and 14, but I want to return only product id 12 because I only want the product id which is not in other categories. In my filter category id 4 returns product ids 10,12 and 14 but I only want to product id 4 because 10 and 14 belong to other categories which I don't want. I only want to product id 12 in filter. Which filter I used ?
$catIds = array(4);
$notCatIds = array(3, 10);
$productCollection = Mage::getResourceModel('catalog/product_collection')
->setStoreId(0)
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left')
->addAttributeToFilter('category_id', array('in' => $notCatIds))
->addAttributeToFilter('category_id', array('in' => $catIds))
->addAttributeToFilter('category_id', array('nin' => $notCatIds))
->addAttributeToFilter('category_id', array('nin' => array(2)))// 2 is default category id
->addAttributeToSelect('*');
$productCollection->getSelect()->group('product_id')->distinct(true);
echo '<pre>';
print_r($productCollection->getData());