Here is a sample url from my company's Magento site (and we're obviously using stores in the URL hence the smi000.. code)


I understand that the category id is 312834, and the product id is 35830. I understand how to use Mage::helper->getURL() to get the URL, but how do I get the product ID using magento code (i.e. the "Magento Way"?)

1 Answer 1


You could get the product id from the core_url_rewrite table using the url for this, try this:

$url = Mage::helper->getURL();
$rewrite = Mage::getModel('core/url_rewrite')

$productId = $rewrite->getProductId();

$product = Mage::getModel('catalog/product')->load($productId);

Also you could get the id from the url directly (no extra query to the DB) like this:

$productId = $this->getRequest()->getParam('id');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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