0

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.

1 Answer 1

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, privacy policy and cookie policy

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