3

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));

2 Answers 2

8

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));
3

To get disabled products while you have enabled flat structure, Try this line before your query

Mage::app()->getStore()->setConfig('catalog/frontend/flat_catalog_product', 0);

and then you can use your normal query

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

This will by pass flat structure and get you data from EAV structure

2
  • 1
    Perfect answer. Much easier to apply!
    – Roy Toledo
    Sep 5, 2019 at 20:30
  • Thanks @RoyToledo :) Sep 6, 2019 at 5:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.