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();
endforeach;
Method 2
This way we can retrieve currently loaded product’s id.
$product_id = Mage::registry(‘current_product’)->getId();
Did this post help you?
Tutsplanet brings in-depth and easy tutorials to understand even for beginners. This takes a considerable amount of work. If this post helps you, please consider supporting us as a token of appreciation:
- Just want to thank us? Buy us a Coffee
- May be another day? Shop on Amazon using our links.
Your prices won't change but we get a small commission.
Leave a Reply