Get all disabled products programmatically in Magento

By | February 21, 2014

Get all disabled products from Magento using product collection:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
set_time_limit(0);
error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors",'On');

require_once 'app/Mage.php';
umask(0);
Mage::app('default');

$products = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect('*')
    ->addFieldToFilter('status',Mage_Catalog_Model_Product_Status::STATUS_DISABLED);

$products->load();
foreach($products as $product) {
    echo $product->getData('sku')."<br />";
    //var_dump($product->getStatus());
}
?>

Get all disabled products from Magento using Database SQL query:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
set_time_limit(0);
error_reporting(E_ALL ^ E_NOTICE);
ini_set("display_errors",'On');

require_once 'app/Mage.php';
umask(0);
Mage::app('default');
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

$conn = Mage::getSingleton('core/resource')->getConnection('core_write');

$catSQL = "SELECT *
FROM `itshot_catalog_product_entity_int`
WHERE `attribute_id` =84  // status=84 (see status id from attributes)
AND `value` =2  // disabled value=2
//AND `entity_id` >30970"; // if you want to show result from range
$categories = $conn->fetchAll($catSQL);
foreach ($categories as $product)
{
    $id = trim($product["entity_id"]);
}
?>

Leave a Reply