Reputation: 823
Is there a way, in Magento, to get the productID of the product currently being edited on the Admin backend?
I found this:
Mage::registry('current_product');
but it doesn't seem to get the one being edited.
Edit: If it makes any difference, I'm trying to get it from an extension listening for the event:
catalog_product_gallery_upload_image_after
Upvotes: 1
Views: 2300
Reputation: 23205
That should work, as should Mage::registry('product')
, as long as it is requested after Mage_Adminhtml_Catalog_ProductController::_initProduct()
is called.
Mage::app()->getRequest()->getParam('id')
should also work.
Edit based on event
The event being observed is dispatched in response to a JS-originated request. The controller action is unaware of the calling context, and there is no product registered in the registry. Logging the request params or possibly the referrer may give insight.
Upvotes: 1
Reputation: 2334
The current product's ID is in the URL. You can retrieve it as a parameter like so:
$productId = Mage::app()->getRequest()->getParam('id');
If you want to load the product as an object, store that ID and use
$product = Mage::getModel('catalog/product')->load($productId);
Edit: It looks like you're using an observer. The observer file itself I assume does not extend any part of Magento. (Is this the file? http://svn.magentocommerce.com/source/branches/1.7/app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GalleryController.php) Try obtaining the action and getting the request that way
$action = $observer->getAction();
$productId = $action->getRequest()->getParam('id');
Upvotes: 4