Skip to content

Instantly share code, notes, and snippets.

@yogeshdubey2006
Created December 29, 2018 12:25
Show Gist options
  • Save yogeshdubey2006/5b308896155a1907a21d5d2db9e5cce9 to your computer and use it in GitHub Desktop.
Save yogeshdubey2006/5b308896155a1907a21d5d2db9e5cce9 to your computer and use it in GitHub Desktop.
Magento 2 get product id to my custom module
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product'); //get current product
echo $product->getId();
echo $product->getName();
?>
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productid = $this->getRequest()->getParam('id');
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($productid);
echo $product;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment