0

I have some special functions that need to run per specific products in magento. Is there a way to get the product ID via PHP in the single product page template?

2

1 Answer 1

0
<path_to_your_template_folder>/template/catalog/product/view.phtml
$_sku     = $this->getItem()->getSku();
$_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $_sku);
$_product->getEntityId(); // here is your ID

Taken [shamelessly] from this blog post: http://till.klampaeckel.de/blog/archives/126-Magento-Loading-the-product-from-a-template.html

Also, I saw this suggestion:

Mage::getModel('catalog/product')->getIdBySku($sku);

Not the answer you're looking for? Browse other questions tagged or ask your own question.