Magento 1.8 – How to Get Disabled or Inactive Products from Flat Catalog

catalogmagento-1.8PHP

I am trying to get all disabled products from magento using the following code but it returns only enabled products. I have enabled Flat Catalog Product options. Is there any way to get disabled configurable products using mysql or magento code?

$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('type_id', array('eq' => 'configurable'))
->addAttributeToSelect('*')
->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED));

Best Answer

The disabled products are not indexed in the flat table.
Take a look at Mage_Catalog_Model_Product_Flat_Indexer::updateProductStatus(). This is called sometime during the indexing process.

public function updateProductStatus($productId, $status, $store = null)
{
    if (is_null($store)) {
        foreach (Mage::app()->getStores() as $store) {
            $this->updateProductStatus($productId, $status, $store->getId());
        }
        return $this;
    }

    if ($status == Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
        $this->_getResource()->updateProduct($productId, $store);
        $this->_getResource()->updateChildrenDataFromParent($store, $productId);
    }
    else { //IF the product is disabled it is removed from the flat tables
        $this->_getResource()->removeProduct($productId, $store);
    }

    return $this;
}

So you can get the disabled products only by using the EAV tables.
Try this:

$collection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('type_id', array('eq' => 'configurable'))
->addAttributeToSelect('*')
->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED));