Magento – Magento – foreach simple product show name, sku and stock quantity

adminstock

Magento – foreach simple product show name, sku and stock quantity?

Hi, I am trying to accomplish the following. I would like a simple PHP script to show/export: foreach simple product name, sku, stock quantity, stock status

And pref also for configurable products (same but then summed)

I've come accross many good import scripts, but not a small sript to actually show the current stock status. The problem is that we have an employee who just doesnt understand data profiles etc: the problem arises btw when they have to open FTP to look up the file

https://stackoverflow.com/questions/8533426/daily-inventory-update-through-remote-ftp-file

Question: Any ideas how I can create a small script to show all current stock levels per product?

Best Answer

This should work to quickly grab everything you want. There may be a better way to do it.

<?php 
// Load Magento
require_once '../app/Mage.php';
umask(0);
Mage::app('default');


//get the collection filter the simple products & join the cataloginventory/stock_item table
$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('sku')->addAttributeToFilter('type_id', 'simple')->joinField(
    'qty',
    'cataloginventory/stock_item',
    'qty',
    'product_id=entity_id',
    '{{table}}.stock_id=1',
    'left'
) ;
?>
<html>
<head></head>
<body>
<table>
<?php 
foreach ($collection as $product) {
    echo "<tr><td>".$product->getSku()."</td><td> ".(int)$product->getQty()."</td></tr>";
};




?>
</table>
</body></html>
Related Topic