In my block I have provide a function to fetch product details from product Id. Code in block file
public function getProductById($pid)
{
$product = $this->_productRepository->getById($pid);
return $product->getUrlModel()->getUrl($product);
}
And in .phtml file I have provided
$returnProdId = $block->getProductById($returnItems['products']);
print_r($returnProdId);
But the result is not as expected.Result which I am getting is http://localhost/magento2/index.php/catalog/product/view/id/1420/s/iris-workout-top-xs-red/
Please help on the same.