0

I want to get product's url so i use getProductUrl() in result its return a url address that seems be correct but its not,When i want to open it the store return 404 not found error.

$product = Mage::getModel('catalog/product')->load($productId);
$url => $product->getProductUrl();

//It's return

// http://mg1.dev/index.php/catalog/product/view/id/905/s/plaid-cotton-shirt-royal-blue-l/

3 Answers 3

2

I hope this will help you. It works for me

$products=Mage::getModel('catalog/product')->load($productid);
return $products->getUrlModel()->getProductUrl($products);
0

First try to do full indexing of your Magento site.

If above one is not solving your problem then instead of using getProductUrl() try to use getUrlPath()

Another solution is:

$product = Mage::getModel('catalog/product')->load($productId);
$product->addUrlRewrite()
$url = $product->getProductUrl();
0

From here it is hard to tell that what is causing this problem but you can try following things. These things may help you.

You can try following code to get URL -

$product = Mage::getModel('catalog/product')->load($productId);
$url = $product->getUrlModel()->getProductUrl($product)

And check whether the product is enabled or disabled from settings. Product must be enabled in order to show the product view page.

If above does not work then you can get the URL path and construct the URL by yourself like following.

$url = <base_url>/$product->getUrlPath();

Print $product->getData() array and you can dig out something that might help you.

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.