Magento – get all disabled products in current category

magento-1.9product-collection

How do I get all disabled products in the current category

<?php 
    $categoryIds = array(956);//category id
    $products = Mage::getResourceModel('catalog/product_collection')
    ->addCategoryFilter(Mage::getModel('catalog/category')->load($categoryIds));
    $collection = Mage::getModel('catalog/product')->getCollection()
        ->addFieldToFilter('entity_id', array('in' => $products->getAllIds()))
    ->addAttributeToSelect('*');
 ->addFieldToFilter('status',Mage_Catalog_Model_Product_Status::STATUS_DISABLED);

?>

Best Answer

When you want to get products from category using $productCollection->addCategoryFilter() or using $category->getProductCollection() query use product to category connection INDEX table. When you run re index that product category connection INDEX table is populated only with Enabled porducts, and you can not get disabled products on that way.

$categoryId = 956; // a category id that you can get from admin

For Disable Product

$collection = Mage::getModel('catalog/product')
->getCollection()
 ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
->addAttributeToSelect('*')
->addAttributeToFilter('status', array('eq' => 2))
 ->addAttributeToFilter('category_id',  array('eq' => $categoryId));