1

I have a template file that 'gets' the product url so that I can produce a link to the product. However, the url called is not the SEO friendly version. Can anyone suggest an edit to the code below so that I can get the preferred SEO friendly URL instead?

Current URL

example.com/catalog/product/view/id/419/category/252

Preferred SEO Friendly URL

examples.com/my-product.html

PHTML - My Current Code

<?php $product = $categoryProducts->getFirstItem();?>
 <a href="<?php echo $product->getProductUrl()?>">Product Link</a>
<?php endif;?>
2

As per as your code,you have tried to get product($product) 's Seo Url from a product collection ($categoryProducts).

In order to get seo url you need to add addUrlRewrite() function to that collection ($categoryProducts).

So changes

<?php $product = $categoryProducts->getFirstItem();?>

to

<?php 
$categoryProducts->addUrlRewrite();
$product = $categoryProducts->getFirstItem();?>

Also,please check Magento indexing Management is working or not at system

| improve this answer | |

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