0

I'm trying to rewrite the following class from a 3rd party module:

Magestore_Storelocator_Block_Adminhtml_Storelocator_Edit_Tab_Generalinfo

I've declared the module in Holy_Storelocator.xml.

<config>
  <modules>
    <Holy_Storelocator>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
      <depends>
          <Magestore_Storelocator />
      </depends>
    </Holy_Storelocator>
  </modules>
</config>

Then I created a config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Holy_Storelocator>
      <version>0.1.0</version>
    </Holy_Storelocator>
  </modules>
  <global>
    <helpers>
      <storelocator>
        <class>Holy_Storelocator_Helper</class>
      </storelocator>
    </helpers>
    <blocks>
        <storelocator>
            <rewrite>
                <adminhtml_storelocator_edit_tab_generalinfo>Holy_Storelocator_Block_Adminhtml_Storelocator_Edit_Tab_Generalinfo</adminhtml_storelocator_edit_tab_generalinfo>
                <!-- Magestore_Storelocator_Block_Adminhtml_Storelocator_Edit_Tab_Generalinfo -->
            </rewrite>
        </storelocator>
    </blocks>
  </global>
</config>

And finally I created the class:

<?php
class Holy_Storelocator_Block_Adminhtml_Storelocator_Edit_Tab_Generalinfo extends Magestore_Storelocator_Block_Adminhtml_Storelocator_Edit_Tab_Generalinfo
{
    protected function _prepareForm() {
    // code ommitted

        return parent::_prepareForm();
    }
}
1

You should still extend the magestore class, just use

return Mage_Adminhtml_Block_Widget_Form::_prepareForm();

instead of

return parent::_prepareForm();

This will skip the parent class's _prepareForm but still keep the rest of the inheritance chain intact.

  • thanks. In the end I used an observer but this is good to know – Holly Oct 3 '16 at 9:58
0

It turned out that the return parent::_prepareForm(); in my class was calling the original class which I was trying to override and ovewriting my changes.

To fix the issue I made my class extend from extend from Mage_Adminhtml_Block_Widget_Form

<?php
class Holy_Storelocator_Block_Adminhtml_Storelocator_Edit_Tab_Generalinfo extends Mage_Adminhtml_Block_Widget_Form
{
    //code here
}

So I guess return parent::_prepareForm(); is a common cause for messing up Magento Class re-writes.

I found that an observer was a better method to use here afterall.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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