I have create an Observer function which is call after product save but having some issues with product url.

Getting product like:

$product = $observer->getEvent()->getProduct();

Getting product url path:

**$product->getUrlPath();  //Return empty path**

$product->getProductUrl(); //Show error for function

//Finally I have used it

Mage::app()->setCurrentStore('default'); //set the default storeview
$url = Mage::helper('catalog/product')->getProductUrl($product->getId()); //get url for .html
Mage::app()->setCurrentStore('admin'); //set the admin store again

But now the issue is url is shown as :

instead of 


I want product .html url else url_path in observer.

1 Answer 1


I think you should fire the query directly on URL Rewrite table.

$productUrl = Mage::getResourceModel('core/url_rewrite')
        ->getRequestPathByIdPath('product/' . $productId, $storeId);

ou can try getting the product id as

$product = $observer->getEvent()->getProduct();
$productId = $product->getId();

Hope it was helpful. Thanks

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.