3
votes

I've spent hours trying to override the Magento block for the "Add store" and "Edit store" pages in an extension, to add another text box to it. After Going through books and Googling, I've found several solutions which people say are working, however not for me.

One recommendation was this one.

I've copied the supposedly correct solution from Lee Saferite which works for the original poster but not for me. Of course, I changed the values to the class I'm overriding and the new modified class.

My config.xml (the relevant part):

<global>
    <blocks>
      <adminhtml>
        <rewrite>
          <system_store_sdit_form>Nintera_General_Block_StoreEdit</system_store_sdit_form>
        </rewrite>
      </adminhtml>
    </blocks>
    <resources></resources>
    <helpers>
      <Nintera_General>
        <class>Nintera_General_Helper</class>
      </Nintera_General>
    </helpers>
  </global>

And the block class located at Nintera/General/Block/StoreEdit.php:

class Nintera_General_Block_StoreEdit extends Mage_Adminhtml_Block_System_Store_Edit_Form
{
    /**
     * Prepare form data
     *
     * return Mage_Adminhtml_Block_Widget_Form
     */
    protected function _prepareForm()
    { ... }
}

This class contains new input fields. The fields show up perfectly if I modify the original core file at:

app/core/Mage/Adminhtml/Block/System/Store/Edit.php

But I really want my extension to override it. If necessary I can post my entire config.xml but it's mostly creating a top level admin menu and specifies extension info, not much else.

Any ideas on what goes wrong? A solution would be HIGHLY appreciated!

2

2 Answers

10
votes

Shown below, with a slight modification. It appears that you've misspelt "edit" as "sdit".

<global>
   <blocks>
      <adminhtml>
        <rewrite>
          <system_store_edit_form>Nintera_General_Block_StoreEdit</system_store_edit_form>
        </rewrite>
      </adminhtml>
   </blocks>
</global>

Also keep in mind that if you want to call other blocks using the Mage::getModel("nintera_general/myblock") syntax, you'll need to add your own blocks to that code as well, as shown below.

<global>
   <blocks>
      <adminhtml>
        <rewrite>
          <system_store_edit_form>Nintera_General_Block_StoreEdit</system_store_edit_form>
        </rewrite>
      </adminhtml>
      <nintera_general>
         <class>Nintera_General_Block</class>
      </nintera_general>
   </blocks>
</global>
3
votes

After Reading several threads I've found the solution for this issue of overriding Mage_Adminhtml_Block_Widget_Grid.

As mentioned in this thread
"You can override (rewrite) in config only the blocks that are instantiated. You cannot inject anything into classes hierarchy as it is not supported by PHP"

I wanted to override the method protected function _addColumnFilterToCollection($column)

for the extended hierarchy of Mage_Adminhtml_Block_Sales_Order_Grid.

Instead of overriding Mage_Adminhtml_Block_Widget_Grid I override the class Mage_Adminhtml_Block_Sales_Order_Grid and place my function there.

And for me this works fine.