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?
1 Answer
<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);
if(something) { //do this }
in php, you would just need to look at the script/page responsible for product output.