Magento 1.9 – Get All Products of a Specific Category Without Child Categories

categorymagento-1.9product-collection

I want to get specific category product collection, not include it's child category product in it .

Below code which i have tried.

$category = Mage::getModel('catalog/category')->load(5);
 $getCollections = $category->getProductCollection()
         ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
         ->addAttributeToFilter('visibility', 4)
         ->addAttributeToSelect('*');

can any one please help me ?

Best Answer

Try this:

$category = Mage::getModel('catalog/category')->load(5);
$isAnchorFlag = $category->getIsAnchor();
$category->setIsAnchor(false);
$getCollections = $category->getProductCollection()
         ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
         ->addAttributeToFilter('visibility', 4)
         ->addAttributeToSelect('*');
$category->setIsAnchor($isAnchorFlag);
Related Topic