Get product id in magento

We can get product id from product object in Magento.

Method 1

You can get the product ID from a collection

$_productCollection = Mage::getModel(‘catalog/product’)->getCollection();

foreach ($_productCollection as $_product):
$productId = $_product->getId();

Method 2

This way we can retrieve currently loaded product’s id.

$product_id = Mage::registry(‘current_product’)->getId();
Editorial Staff

Editorial Staff at tutsplanet is a dedicated team to write various tutorial articles.