How To Get Current Magento 2 Product Info Programmatically

How to get current Magento 2 product info programmatically from Block class

You can use “Magento\Framework\Registry ” to retrieve current magento 2 product object.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$registry = $objectManager->get(‘\Magento\Framework\Registry’);
$product = $registry->registry(‘current_product’);

Get product’s name

$productName = $product->getName();

Get product’s sku

$productName = $product->getSku();

Get product’s ID

$productName = $product->getId();

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments