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.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With