Question

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 :
https://local.com/index.php/catalog/product/view/id/290/s/surestep-pro-diabetic-test-strips-50-strips-professional-care/

instead of 

http://local.com/surestep-pro-diabetic-test-strips-50-strips-professional-care.html

I want product .html url else url_path in observer.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top