magento,  MAGENTO2

How to get the SKU of product in phtml magento2 from given product Id.

Through the help of Object Manager we can get SKU of the product if we have product id.

 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();  
 $productRepository = $objectManager->get('\Magento\Catalog\Model\ProductRepository');
 $b;
 $productd = $objectManager->get('Magento\Catalog\Model\Product')->load($b);  // product id 
 $sku = $productd->getSku();

Leave a Reply

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

4 × 5 =