Skip to main content
added 141 characters in body
Source Link

Try to using this

    $productId = 1;

    $productRepository = $objectManager->get('Magento\Catalog\Api\ProductRepositoryInterface');
    $product = $productRepository->getById($productId);
    $product->getProductUrl();

It just an example don't use objectManager directly you can inject the class Magento\Catalog\Api\ProductRepositoryInterface to constructor

Try to using this

    $productId = 1;

    $productRepository = $objectManager->get('Magento\Catalog\Api\ProductRepositoryInterface');
    $product = $productRepository->getById($productId);
    $product->getProductUrl();

Try to using this

    $productId = 1;

    $productRepository = $objectManager->get('Magento\Catalog\Api\ProductRepositoryInterface');
    $product = $productRepository->getById($productId);
    $product->getProductUrl();

It just an example don't use objectManager directly you can inject the class Magento\Catalog\Api\ProductRepositoryInterface to constructor

added 52 characters in body
Source Link

Try to using this

    $productId = 1;

    $productRepository = $objectManager->get('Magento\Catalog\Api\ProductRepositoryInterface');
    $product = $productRepository->getById(1$productId);
    $product->getProductUrl();

Try to using this

$productRepository = $objectManager->get('Magento\Catalog\Api\ProductRepositoryInterface');
$product = $productRepository->getById(1);
$product->getProductUrl();

Try to using this

    $productId = 1;

    $productRepository = $objectManager->get('Magento\Catalog\Api\ProductRepositoryInterface');
    $product = $productRepository->getById($productId);
    $product->getProductUrl();
Source Link

Try to using this

$productRepository = $objectManager->get('Magento\Catalog\Api\ProductRepositoryInterface');
$product = $productRepository->getById(1);
$product->getProductUrl();