Magento 1.9 – How is the Quantity Loaded from Database?

databaseinventorymagento-1.9stock

Qty on the database tables cataloginventory_stock and cataloginventory_stock_item are different from Magento admin page.
I'm assuming there is a problem to load qty from the database.

I want to know how to load qty information from database to Magento admin page.

Thank you

Best Answer

$products = Mage::getModel('catalog/product')
    ->getCollection()
    //->addAttributeToSelect('*')
    ->addAttributeToSelect(array('name', 'thumbnail', 'weight' ,'price','description'))
    ->joinField(
        'qty',
        'cataloginventory/stock_item',
        'qty',
        'product_id=entity_id',
        '{{table}}.stock_id=1',
        'left'
    );

foreach ($products as $product) {
    $p['products'][] = array(
        'id'            => $product->getId(),
        'sku'           => $product->getSku(),
        'name'          => $product->getName(),
        'description'   => $product->getDescription(),
        'weight'        => $product->getWeight(),
        'created at'    => $product->getCreatedAt(),
        'pirce'         => Mage::helper('core')->currency($product->getPrice(), true, false), //." ".$currencyCode,
        'qty'           => $product->getQty(),
    );
}

Check this link for more Get product stock quantity in magento

Related Topic