4

How to get current product ID in Admin Panel / Catalog / Manage Products / Tab ?

enter image description here

I have a custom product tab and no idea how to get current product ID.

In frontend I would do something like this:

<?php $_product = $this->getProduct(); ?>
<?php echo $_product->getId() ?>
enloz
  • 5,704
  • 9
  • 37
  • 56

3 Answers3

9

If you look at Mage_Adminhtml_Catalog_ProductController you will see the product in question twice, so either of these will work:

$product = Mage::registry('product');
echo $product->getId();

$product = Mage::registry('current_product');
echo $product->getId();
clockworkgeek
  • 37,650
  • 9
  • 89
  • 127
1

You can find the product ID in the URL:

http://yourmagento.install.com/index.php/admin/catalog_product/edit/id/[here_it_is]/key/35db6b1fdadbcf2867d06150blahblahblahblahblahc19697f1a28cd141051/

Failing that, I'll have a look at what template file you'll need to edit.

EDIT:

app/design/adminhtml/default/default/template/catalog/product/edit.phtml

After this line:

<h3 class="icon-head head-products"><?php echo $this->getHeader() ?></h3>

Put this:

<?php if($this->getProductId()){ echo $this->getProductId(); } ?>
Magento Guy
  • 2,493
  • 1
  • 16
  • 13
0
$this->getRequest()->getParam(’id’);