Skip to content

Instantly share code, notes, and snippets.

@gelanivishal
Created November 29, 2016 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gelanivishal/2f806b8195112ce41d4543a7da8c8cb6 to your computer and use it in GitHub Desktop.
Save gelanivishal/2f806b8195112ce41d4543a7da8c8cb6 to your computer and use it in GitHub Desktop.
Get product stock quantity in magento
<?php
$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,
//get qty
'qty' => $product->getQty(),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment