You can get product data by product id using below code snippets.
<?php
namespace MagemonkeysProductCollectionBlock;
class Product extends MagentoFrameworkViewElementTemplate
{
/**
* Constructor
*
* @param MagentoFrameworkViewElementTemplateContext $context
* @param array $data
*/
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoCatalogApiProductRepositoryInterface $productRepository,
array $data = []
) {
$this->productRepository = $productRepository;
parent::__construct($context, $data);
}
/**
* Get Product by Id
* @param int
* @return MagentoCatalogModelProduct $product
*/
public function getProduct($id)
{
return $this->productRepository->getById($id);
}
}
Just write the below code inside the template file(.phtml file)
$product_id = 1; $product = $block->getProduct($product_id); echo $product->getName(); // product name echo $product->getSku(); // product sku

