Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

how to get category values in overloaded catalog controller
 
arunicbe
Jr. Member
 
Total Posts:  19
Joined:  2011-11-10
 

I am trying to write a audit log for catalog creation / updation in the admin section.

I created a overload for product controller. I need to get the details of the product created or updated. I have given my model code
below. How do I get the product details from Parent controller?

class Mage_Override_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController
{
public function saveAction(){
parent::saveAction();
/*
audit log code goes here
*/
}

public function editAction(){
parent::saveAction();

/*
audit log code goes here
*/
}
}

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

Hello
In your new class you have access to all the methods (public and protected) from Mage_Adminhtml_Catalog_ProductController, because your class is a child of that one (I’m just stating the obvious but I just wanted to be clear).
In Mage_Adminhtml_Catalog_ProductController class there is a method called _initProduct that should return the product being edited (or an “empty” instance of the product model if you add a product).
If you already called the _initProduct method you have the product instance available in the Mangento registry so you don’t have to init the product twice.

You can retrieve it like this:

$product Mage::registry('product');
//or
$product Mage::registry('current_product');

Marius.

 
Magento Community Magento Community
Magento Community
Magento Community
 
arunicbe
Jr. Member
 
Total Posts:  19
Joined:  2011-11-10
 

Hi,

Thanks. It worked.

 
Magento Community Magento Community
Magento Community
Magento Community
 
arunicbe
Jr. Member
 
Total Posts:  19
Joined:  2011-11-10
 

Is this method works for Category also?

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

Hello
Yes it does.
You have a similar method for loading the category called _initCategory and if that was already called you have the current category available in

Mage::registry('category');
//or
Mage::registry('current_category');

Marius.

 
Magento Community Magento Community
Magento Community
Magento Community
 
arunicbe
Jr. Member
 
Total Posts:  19
Joined:  2011-11-10
 

Thanks for your quick reply.

I have one more question. As I mentioned in the first post, I am writing an audit log.

Can I apply the same logic for all objects I need to track? Say, Attributes, Promotions etc.

Thanks again.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

Well it’s not the same logic for all, but it’s something similar.
You are always going to have in the registry the object you are editing. You just need to find the right key. For example for promo rules you have this:  Mage::registry(’current_promo_quote_rule’).
But there isn’t always a method called _init{Entity}. I think you have to take a look in the editAction() method of evey controller you are trying to override to see how the current entity is retrieved.

Marius.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top