0

So I'm writing a module that would rewrite this class: Mage_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Attributes_Special.

It rewrites the getElementHtml() method.

My question is, how do I reference this in my modules main etc/config.xml? I would normally think it would be done like this:

<config>
    <global>
      <blocks>
        <bundle>
            <rewrite>
                <adminhtml_catalog_product_edit_tab_attributes>MyNamespace_MyModuleName_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Attributes</adminhtml_catalog_product_edit_tab_attributes>
            </rewrite>
        </bundle>
      </blocks>
    </global>
</config>

Is that config.xml done correctly? If not, how should I do it?

2 Answers 2

5

Close.

<config>
    <global>
      <blocks>
        <bundle>
            <rewrite>
                <adminhtml_catalog_product_edit_tab_attributes_special>MyNamespace_MyModuleName_Bundle_Block_Adminhtml_Catalog_Product_Edit_Tab_Attributes</adminhtml_catalog_product_edit_tab_attributes_special>
            </rewrite>
        </bundle>
      </blocks>
    </global>
</config>
2

We can rewrite a "deeply" nested block as like a "leastly" nested block. :)

Suppose the method that you need to rewrite a block Namespace_Modulename_Block_Nest1_Nest2_Nest3_Nest4_Nest5, then your rewrite should look like

<config>
    <global>
      <blocks>
        <bundle>
            <rewrite>
                <nest1_nest2_nest3_nest4_nest5>MyNamespace_MyModuleName_Block_Namespace_Mynest1_Mynest2_Mynest3_Mynest4_Mynest5</nest1_nest2_nest3_nest4_nest5>
            </rewrite>
        </bundle>
      </blocks>
    </global>
</config>

and your block definition should look like this

Location : app/code/local/MyNamespace/MyModuleName/Block/Namespace/Mynest1/Mynest2/Mynest3/Mynest4/Mynest5.php

<?php
class MyNamespace_MyModuleName_Block_Namespace_Mynest1_Mynest2_Mynest3_Mynest4_Mynest5 
    extends Namespace_Modulename_Block_Nest1_Nest2_Nest3_Nest4_Nest5
{
   //rewriting method comes here.
}

You can rewrite the block anywhere in you Module's block scope. It is not a strict rule your block definition should look like MyNamespace_MyModuleName_Block_Namespace_Mynest1_Mynest2_Mynest3_Mynest4_Mynest5. Your rewrite may be MyNamespace_MyModuleName_Block_Namespace_Mynest5. For that case, the location your file resides and hence the classname changes accordingly.

Hope it gives some general idea

2
  • 1
    Actually I found that in the <rewrite> element you don't do <namespace_nest1_nest2_etc> you just do <nest1_nest2_etc> and also by convention Namespace comes before Block in the actual value like: MyNamespace_MyModuleName_Namespace_Block_Nest1_Nest2_etc. (though it doesn't really matter because you can technically call it whatever you want I think, it just comes down to convention).
    – CommaToast
    Commented Jul 29, 2014 at 19:07
  • @CommaToast: Thanks for pointing out the error. I edited my answer. I am normally use Mynamespace_Mymodulename_Block_Namespce_etc to define my rewrite block. As I already mentioned at last part of my answer, its not at all a strict rule. Thanks again for your time. :) Commented Jul 30, 2014 at 0:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.