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

Overriding
 
Johanna
Jr. Member
 
Total Posts:  7
Joined:  2007-11-28
 

Hello everyone,

I’m currently working on adding countries to Tax Rates, and thus would like to override the Mage_Adminhtml_Block_Tax_Rate_Form_Add class in order to add the Country-dropdown to the Edit/Add Tax Rate page.

I am however stuck on how the config.xml should be formed with the override so “deep” in the Block-structure, so far I’ve fumbled with the code-snippet below and different varietes, but I’m not getting it to work… could someone please help me out on how the xml-structure should be?  smile

<?xml version="1.0"?>
<config>
    <
modules>
        <
Mage_MyAdminhtml>
            <
version>0.1.0</version>
        </
Mage_MyAdminhtml>
    </
modules>
    <global>
        <
blocks>
            <
adminhtml>
                <
tax>
                    <
rate>
                        <
form>
                            <
rewrite>
                                <
add>
                                    
Mage_MyAdminhtml_Block_Tax_Rate_Form_Add
                                
</add>
                            </
rewrite>
                        </
form>
                    </
rate>
                </
tax>
            </
adminhtml>
        </
blocks>
    </global>
</
config>

‘Nother question;
What is the recommended way to go about with overriding Admin-templates?

 
Magento Community Magento Community
Magento Community
Magento Community
 
SeL_
Magento Team
 
Avatar
Total Posts:  1140
Joined:  2007-10-10
Paris, France
 

Hi Johanna,

I didn’t try overriding admin templates, but i think you should try with this code:

<?xml version="1.0"?>
<config>
    <
modules>
        <
Mage_MyAdminhtml>
            <
version>0.1.0</version>
        </
Mage_MyAdminhtml>
    </
modules>
    <global>
        <
blocks>
            <
adminhtml>
                <
rewrite>
                    <
tax_rate_form_add>Mage_MyAdminhtml_Block_Tax_Rate_Form_Add</tax_rate_form_add>
                </
rewrite>
            </
adminhtml>
        </
blocks>
    </global>
</
config>

Tell us if it’s ok with this.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

@SeL: yep, this is correct smile

@Johanna: for frontend that would be changing the default theme in admin, for admin it is not available currently.
So for now you can temporarily change it manually in app/code/core/Mage/Adminhtml/Controller/Action.php in function preDispatch:

Mage::getDesign()->setArea('adminhtml')
    ->
setPackageName('default')
    ->
setTheme('johanna');

Now, in app/design/adminhtml/default/johanna/templates/ you should be able to put your custom templates on exactly same relative pathes as the original ones. This was not tested, so it might be less straghtforward.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Johanna
Jr. Member
 
Total Posts:  7
Joined:  2007-11-28
 

Thanks Seldon, your suggestion worked great. smile

However I have another overriding problem.

In my attempts to add countries to Tax Rates, I need to override

- Mage_Tax_Model_Mysql4_Rate_Collection
- Mage_Tax_Model_Mysql4_Rate
- Mage_Tax_Model_Rate_Data
- Mage_Tax_Model_Mysql4_Rate_Data

The first three overrides work great, the last one I cannot get to override properly.
I use the following xml-structure.

<models>
    <
tax_mysql4_rate>
        <
rewrite>
             <
collection>Mage_MyTax_Model_Mysql4_Rate_Collection</collection>
        </
rewrite>
    </
tax_mysql4_rate>
    <
tax_mysql4>
        <
rewrite>
             <
rate>Mage_MyTax_Model_Mysql4_Rate</rate>
        </
rewrite>
    </
tax_mysql4>
    <
tax>
        <
rewrite>
             <
rate_data>Mage_MyTax_Model_Rate_Data</rate_data>
        </
rewrite>
    </
tax>
     <
tax_mysql4_rate>
        <
rewrite>
             <
data>Mage_MyTax_Model_Mysql4_Rate_Data</data>
        </
rewrite>
    </
tax_mysql4_rate>
</
models>

I have tried with different variaties such as

<tax>
    <
rewrite>
        <
mysql4_rate_data>Mage_MyTax_Model_Mysql4_Rate_Data</mysql4_rate_data>
    </
rewrite>
</
tax>
,
<tax_mysql4>
    <
rewrite>
        <
rate_data>Mage_MyTax_Model_Mysql4_Rate_Data</rate_data>
    </
rewrite>
</
tax_mysql4>
,
<tax_mysql4_rate>
    <
rewrite>
        <
data>Mage_MyTax_Model_Mysql4_Rate_Data</data>
    </
rewrite>
</
tax_mysql4_rate>

as well as adding

<data>Mage_MyTax_Model_Mysql4_Rate_Data</data>
inside the rewrite-tags of the first <tax_mysql4_rate>.
and adding
<rewrite>
     <
data>Mage_MyTax_Model_Mysql4_Rate_Data</data>
</
rewrite>
to the first <tax_mysql4_rate>.

Also interestingly,

<tax>
    <
rewrite>
         <
rate_data>Mage_MyTax_Model_Rate_Data</rate_data>
    </
rewrite>
</
tax>
works, while
<tax_rate>
    <
rewrite>
         <
data>Mage_MyTax_Model_Rate_Data</data>
    </
rewrite>
</
tax_rate>
does not… As I understood it, should not both of these constructions work?

Can anyone shed some light onto this matter or if there are any conventions or guidelines that I could be referred to, I’m seriously scratching my head over this. smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

Here’s the correct way:

<models>
    <
tax_mysql4>
        <
rewrite>
             <
rate_collection>Mage_MyTax_Model_Mysql4_Rate_Collection</rate_collection>
        </
rewrite>
    </
tax_mysql4>
    <
tax_mysql4>
        <
rewrite>
             <
rate>Mage_MyTax_Model_Mysql4_Rate</rate>
        </
rewrite>
    </
tax_mysql4>
    <
tax>
        <
rewrite>
             <
rate_data>Mage_MyTax_Model_Rate_Data</rate_data>
        </
rewrite>
    </
tax>
     <
tax_mysql4>
        <
rewrite>
             <
rate_data>Mage_MyTax_Model_Mysql4_Rate_Data</rate_data>
        </
rewrite>
    </
tax_mysql4>
</
models>

You need to make sure that 2nd level nodes after <models> have to exist in original models declarations, such as <tax> and <tax_mysql4>

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