cancel
Showing results for 
Search instead for 
Did you mean: 

Overriding Adminhtml block

Overriding Adminhtml block

Hi folks - apologies for the fact variants of this question have been asked before... but after hours of searching and testing I've not had any luck.

 

I'd like to override app\code\core\Mage\Adminhtml\Block\Customer\Edit\Tab\Account.php

 

I have created the override file here: app\code\local\Appio\Customer\Adminhtml\Block\Customer\Edit\Tab\Account.php

 

In the override file:

class Appio_Adminhtml_Block_Customer_Edit_Tab_Account extends Mage_Adminhtml_Block_Customer_Edit_Tab_Account
{ ....

In app\etc\modules\Appio_Customer.xml :

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Appio_Customer>
            <active>true</active>
            <codePool>local</codePool>
        </Appio_Customer>
    </modules>
</config>

and finally in app\code\local\Appio\Customer\etc\config.xml :

<?xml version="1.0" encoding="UTF-8"?>
<config>
	<modules>
		<Appio_Customer>
			<version>1.0.1</version>
		</Appio_Customer>
	</modules>
	<global>
		<blocks>
			<adminhtml>
				<rewrite>
					<customer_edit_tab_account>Appio_Adminhtml_Block_Customer_Edit_Tab_Account</customer_edit_tab_account>
				</rewrite>
			</adminhtml>
		</blocks>
	</global>
</config>

I've tried various permutations of this last config file, switching around tags, adjusting the innermost tag name... but I just can't get it right! The file is not overriden. Any help much appreciated...

8 REPLIES 8

Re: Overriding Adminhtml block

Hi @benk123,

 

Are you using another module that maybe can be apllying the same override?

Re: Overriding Adminhtml block

Thanks @Damian Culotta for the response and apologies for the delay in getting back.

 

Alas I've checked through all other modules and there is nothing else attempting to override the same class.

 

Any other thoughts? Thanks again...

Re: Overriding Adminhtml block

Hi @benk123,

 

I've tested your code and there are some errors.

This code will work.

 

/app/etc/modules/Appio_Customer.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Appio_Customer>
            <active>true</active>
            <codePool>local</codePool>
        </Appio_Customer>
    </modules>
</config>

/app/code/local/Appio/Customer/etc/config.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Appio_Customer>
            <version>1.0.0</version>
        </Appio_Customer>
    </modules>
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <customer_edit_tab_account>Appio_Customer_Block_Adminhtml_Customer_Edit_Tab_Account</customer_edit_tab_account>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
</config>

/app/code/local/Appio/Customer/Block/Adminhtml/Customer/Edit/Tab/Account.php

 

<?php


class Appio_Customer_Block_Adminhtml_Customer_Edit_Tab_Account extends Mage_Adminhtml_Block_Customer_Edit_Tab_Account
{

    public function __construct()
    {
        Zend_Debug::dump(__METHOD__);
        parent::__construct();
    }

}

And the result should be:

Área de trabajo 1_001.png

 

 

 

 

Remember to enable your Magento's logs.

For example, after I've copied yoru module, the exception log said:

 

2017-09-19T17:29:41+00:00 ERR (3): 
exception 'Mage_Core_Exception' with message 'Invalid block type: Appio_Block_Adminhtml_Customer_Edit_Tab_Account'...

Cheers.

Re: Overriding Adminhtml block

Many thanks for your efforts @Damian Culotta, it's much appreciated. But.... still no luck!

  • I've doubled-checked the paths to the files - all correct
  • I've treble checked I am using the exact same code that you provided - I am
  • I've uncommented SetEnv MAGE_IS_DEVELOPER_MODE "true" in .htaccess - no exceptions are thrown.
  • I've searched the whole project for "Customer_Block_Adminhtml_Customer_Edit_Tab_Account", "Mage_Adminhtml_Block_Customer_Edit_Tab_Account" and "<customer_edit_tab_account>" to see if anything else could be interfering - no unexpected occurrences (is there any other way something could be interfering?)

Sorry to be a pain, but if you can think of anything else that'd be really useful.

Thanks again!

Re: Overriding Adminhtml block

Mmmm.. the code you copied is wrong.

You said your block is placed on:

 

app\code\local\Appio\Customer\Adminhtml\Block\Customer\Edit\Tab\Account.php

That means that your module should be Appio_Customer. But your block class is:

class Appio_Adminhtml_Block_Customer_Edit_Tab_Account extends Mage_Adminhtml_Block_Customer_Edit_Tab_Account
{ ....

Appio_Adminhtml should be the module name instead Appio_Customer then. Maybe the right class name should be Appio_Customer_Block_Adminhtml_Customer_Edit...

 

Inside \app\etc\modules\Appio_Customer.xml  you copied this content:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Appio_Customer>
            <active>true</active>
            <codePool>local</codePool>
        </Appio_Customer>
    </modules>
</config>

Again, the module should be Appio_Customer (so the Appio_Adminhtml reference is worng in the php block).

 

Is it possible for you to test my example? I'm pretty sure it will work as you expect.

Re: Overriding Adminhtml block

Thanks @Damian Culotta.

 

Sorry if I wasn't clear. I had copied your example from your previous post exactly. You say: Maybe the right class name should be Appio_Customer_Block_Adminhtml_Customer_Edit..  - because that is the code from your example, that is what I already have now.

 

I had also moved the location of the block to your suggestion too: /app/code/local/Appio/Customer/Block/Adminhtml/Customer/Edit/Tab/Account.php

 

So both go Customer-Block-Adminhtml.

 

In summary: everything is exactly as per your previous post, but still not working. I put a die; in the class constructor, but it loads as normal.

 

I wasn't 100% what you meant when you said that the code I copied was wrong - did you mean your previous post, or my original attempt?

 

Really appreciating the time you're putting into this, Damián.

Re: Overriding Adminhtml block

It's ok.

Your original attempt has code with wrong definitions.

That's why I've suggested to use my example (I've coded those examples into a clean Magento instance)

Re: Overriding Adminhtml block

Hey @Damian Culotta. As I have attempted with your code, and it works on a clean install, I think the problem is in the system my company inherited. I think the plan it to create a new system with Magento 2.0 next year so we may have to wait until then. Thanks anyway though.