Magento get formatted product URL

api, magento

Solution

Are you simply looking for the 'red-bouncy-ball' part of the url?

If so then...

$product->getData('url_key');

When initialising your collection you will need to add the url_key to the select statement...

addAttributeToSelect('url_key')

Problem

I'm trying to get the formatting product url from a Magento product collection. So I want `https://www.myshop.co.uk/red-bouncy-ball.html` Specifically the `red-bouncy-ball` part. I've tried this method: ``` $categoryId = $product->getCategoryIds(); $url = $product->setCategoryId($categoryId)->getProductUrl(); ``` Which gives me: ``` https://www.myshop.co.uk/index.php/catalog/product/view/id/100/ ``` and just ``` $product->getProductUrl() ``` which does the same.

Original source