TransWikia.com

Product URL issue in Observer Magento 1.9

Magento Asked on December 24, 2021

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.

One Answer

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

Answered by Abdul Pathan on December 24, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP