Snippets with the tag: stock

Check stock availability of a product

Description

code to check stock availability of product

Code

protected function _isAvailable(Mage_Sales_Model_Order_Item $orderItem, $qty)
{
	if ($orderItem->getProductId()) {
		$stockItem = Mage::getModel('catalog/product')
				  ->load($orderItem->getProductId())
				  ->getStockItem();

		if ($stockItem->getIsInStock() && (int)$stockItem->getQty() >= $qty) {
			return true;
		}
	}
	return false;
}

Get product stock quantity by id

Description

Get product stock quantity by id

Code

$id = 52;
$_product = Mage::getModel('catalog/product')->load($id);

$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);

print_r($stock->getData());

echo $stock->getQty();
echo $stock->getMinQty();
echo $stock->getMinSaleQty();

Get product stock quantity by sku

Description

Get product stock quantity by sku

Code

$sku = "AB123456789";
$_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);

$stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);

print_r($stock->getData());

echo $stock->getQty();
echo $stock->getMinQty();
echo $stock->getMinSaleQty();