How to get disable product collection whenever flat enable at frontend

The question:

In my system flat setting has been enable for products and as per as magento system magento exclude disable products from product collection whenever flat table is creating. That why we can not get disable product collection on frontend

Now i want to get product collection with disable product at frontend.

Was try below code with set store id as admin for store but it does not works.

Please help me


    ->addAttributeToFilter('amit_status', array(
    'nin' => array(8),

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

take a look at this method Mage_Catalog_Model_Resource_Product_Collection::_construct

protected function _construct()
    if ($this->isEnabledFlat()) {
        $this->_init('catalog/product', 'catalog/product_flat');
    else {

this means that the collection will use flat tables if the result of isEnabledFlat is true.
If you look at the isEnabledFlat you will see that it returns false for the admin otherwise it returns the status of the flat flag for each store. Actually it’s more than that. even if the flag is enabled it may return false if the the flat index is not up to date.

So what you can do is add this at the top of your code:


This will make the collection use the admin store.

If you use this on frontend you will get issues, because you will see the values from admin and you don’t want that.

My second idea is to rewrite the product collection model and change the behavior of the method isEnabledFlat and make it look like this:

public function isEnabledFlat()
    //add this
    if (Mage::registry('use_product_eav')) {
        return false;
    return parent::isEnabledFlat();

then all you have to do is add in your code this Mage::register('use_product_eav', true) before instantiating your collection.
Make sure you call Mage::unregister('use_product_eav') after instantiating it if you don’t want the rest of the page to use eav tables.

Method 2

Since I only need to get the count of some disabled products, I have taken Marius’ first answer and modified it as follows:

// Temporarily set the store to the admin one, otherwise the collection below will omit disabled products
$oldStoreId = Mage::app()->getStore()->getId();
$newStoreId = Mage_Core_Model_App::ADMIN_STORE_ID;

// Search for disabled products
$disabledProducts = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED));

// Reset the store to what it was before

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment