magento,  MAGENTO2

How to get product url from product id magento 2

 $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
 $productRepository = $objectManager->get('\Magento\Catalog\Model\ProductRepository');
$b= 1232;  // the product id 
 $productd = $objectManager->get('Magento\Catalog\Model\Product')->load($b); 
 $sku = $productd->getSku();// getting Sku 
$productData = $productRepository->get($sku);
<a href="<?php echo $productData->getProductUrl(); ?>"> Show product </a>

Leave a Reply

Your email address will not be published. Required fields are marked *

thirteen + 14 =