cancel
Showing results for 
Search instead for 
Did you mean: 

$_product->getUrlKey() returns empty

$_product->getUrlKey() returns empty

Hello,

 

I need to get url_key attribute of a product, but I cannot. 

 

I am calling this:

<?php 
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$key = $_helper->productAttribute($_product, $_product->getUrlKey(), 'url_key')
?>

$product is an element of $_productCollection = $block->getLoadedProductCollection();

 

However, $key get empty. Of course, url key was entered in backend and I do see it in database also.

 

Any help will be appreciated.

 

Thanks

Jaime

 

2 REPLIES 2

Re: $_product->getUrlKey() returns empty

Why do not you just use $_product->getUrlKey() instead of your 2 lines of code?

Re: $_product->getUrlKey() returns empty

getUrlKey does not seem to work. Any other ideas?