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

Rewrite router or controller
 
jhutton
Jr. Member
 
Total Posts:  19
Joined:  2008-06-24
 

Hello,

I’d like to extend the Mage_Adminhtml_CustomerController class with my own. I need to overwrite _initCustomer() so that it uses the correct idFieldname for my customer entity table. In saveAction() in the aforementioned controller, ‘customer_id’ is hard coded into _initCustomer()...(Why doesn’t this just call getEntityIdField() on the customer resource?). I only need that one method in my new controller class and the rest can be inherited.

I’ve tried various rewrite statements in my modules config.xml, but I can’t seem to nail this one down.

Can anyone assist?

Jesse

 
Magento Community Magento Community
Magento Community
Magento Community
 
jhutton
Jr. Member
 
Total Posts:  19
Joined:  2008-06-24
 

Ok, I misunderstood how _initCustomer() was working, because no matter what value I pass in, I can’t seem to init the customer when saving in the admin. Looks like it uses the passed in value to get something from the request params, but I’ve checked in two installs of magento, and from the request logging I set up, the requests look the same. The default install gets a value for $customerId in _initCustomer() on saveAction() and my development install, which has a different customer entity table, does not. The request logs both show empty arrays for the _params property, strangely. And this function works fine if the customer id is passed as a GET param.

Looking further…

 
Magento Community Magento Community
Magento Community
Magento Community
 
jhutton
Jr. Member
 
Total Posts:  19
Joined:  2008-06-24
 

I found the problem. It looks like _prepareForm() in the class Mage_Adminhtml_BlockCustomer_Edit_Form gives the hard coded value ‘entity_id’ to $form->addField(), which doesn’t work for my db, since I’m using an alternate entity table. If I change the function to the below, it works correctly:

protected function _prepareForm()
{
  
...
        
$customer Mage::registry('current_customer');
        
$idField $customer->getResource()->getEntityIdField();

        if (
$customer->getId()) {
            $form
->addField($idField'hidden', array(
                
'name' => 'customer_id',
            ));
            
$form->setValues($customer->getData());
            
Mage::log($customer->getData());
        
}
  
...
}

Can this change be made to Magento so people don’t potentially have to rewrite this after each upgrade? It seems like the right thing to do.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jhutton
Jr. Member
 
Total Posts:  19
Joined:  2008-06-24
 

While I’m at it, ‘entity_id’ is also hard coded into _prepareColumns() in Mage_Adminhtml_Block_Customer_Grid (also in _prepareMassaction(), but I don’t know how that’s used yet..), and I’d like to submit that Magento should be getting that from the customer’s resource model as well.  As long as it’s possible to overwrite entity tables in the config, it seems like hard coding that value as the id field of the entity table is a bad idea.

Any thoughts? Comments?

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