Nov 6, 2014
kalpesh

Magento: Get all products with 0 quantity and In Stock

Magento get all products which have zero quantity and are still In Stock in inventory. Below script will show you all such simple products.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
require_once('app/Mage.php');
umask(0);
Mage::app('admin');
set_time_limit(0);

$productCollection = Mage::getModel('catalog/product')
     ->getCollection()
     ->addAttributeToSelect('*')
     ->joinField('qty',
                 'cataloginventory/stock_item',
                 'qty',
                 'product_id=entity_id',
                 '{{table}}.is_in_stock=1',
                 'left')
     ->addAttributeToFilter('qty', array("eq" => 0));

echo "<h2>Simple Products with 0 quantity and In Stock</h2>";
foreach($productCollection as $product) { //print_r($product->getData());exit;
    if($product->getTypeId() == 'simple')
        echo $product->getName() . " | " . $product->getSku() . "<br>";
}
echo 'Done';
?>

1 Comment

  • nice help. thanks.

Leave a comment

 

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications