I'm looking for a way to get the product URL Key with the product ID.

Actually, I can get the product URL with this code :

$product_id = $_GET["pro"];
$_product = Mage::getModel('catalog/product')->load($product_id); 
$my_product_url = $_product->getProductUrl();

But I just want the URL Key, not the complete URL.



It works.

|improve this answer|||||
  • 3
    you can get it even easier. $_product->getUrlKey() – Marius Sep 29 '15 at 12:04

To get this:

in Collection:

    $collection = Mage::getModel('catalog/product')->getCollection()
        ->addAttributeToFilter('entity_id', array('in'=>array(Your_id)))
        ->addAttributeToFilter('status', 1);

foreach($collection as $col){
  echo $col->getUrlKey();

In load:

$_product = Mage::getModel('catalog/product')->load($product_id); 
$my_product_url = $_product->getUrlKey();
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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