Nov 6, 2014
kalpesh

Magento: Get all products with quantities and Out Of Stock

Magento get all the simple products which have greater than 0 quantity and are still Out of Stock in inventory.

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=0',
                 'left')
     ->addAttributeToFilter('qty', array("gt" => 0));

echo "<h2>Simple Products with >0 quantity and Out of 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

  • Great script. How would you amend the out of stock items with quantities to in stock?

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