0

This is a very common question, but this one is a little different.

I'm trying to overwrite/rewrite a Form block from another module. I'm already rewriting other blocks from this module without issues, I have Extension Conflict module that tells me my override is there, and it can properly display the object trace. I've done a dump of Mage::getConfig()->getNode() with the block I'm overriding and it correctly lists only my override.

My cache is disabled, and I've cleared it multiples times. I've checked a lot of things, and this is either a very weird issue or a very dumb one (that I will punch myself for when I find it).

So, my config file :

<config>
    <modules>
        <Digitagri_Extendedmdn>
            <version>1.0.0</version>
        </Digitagri_Extendedmdn>
    </modules>

    <global>
        <blocks>
            <digitagri_extendedmdn>
                <class>Digitagri_Extendedmdn_Block</class>
            </digitagri_extendedmdn>
            <AdvancedStock>
                <rewrite>
                    <Warehouse_Edit_Form>Digitagri_Extendedmdn_Block_MDN_AdvancedStock_Warehouse_Edit_Form</Warehouse_Edit_Form>
                </rewrite>
            </AdvancedStock>
        </blocks>

The original block that I'm rewriting :

<?php

class MDN_AdvancedStock_Block_Warehouse_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{

    protected function _prepareForm()
    {
        $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
        $form->setUseContainer(true);
        $this->setForm($form);
        return parent::_prepareForm();
    }

}

The new block from my module :

class Digitagri_Extendedmdn_Block_MDN_AdvancedStock_Warehouse_Edit_Form extends MDN_AdvancedStock_Block_Warehouse_Edit_Form
{
    protected function _prepareForm()
    {
        //$form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'));
        //$form->setUseContainer(true);
        //$this->setForm($form);
        Mage::log("Rewrite works!",null,"test.log",true);
        //return Mage_Adminhtml_Block_Widget_Form::_prepareForm();
        //return parent::_prepareForm();
    }

}

And just in case, here's a screenshot of my folder structure :

enter image description here

And that's it. When I add a Mage::log in the original block, it works, but when I do in the override, nothing shows up. Even if I comment the whole rewritten block, the page behaves as usual. It seems to never be called at all, even though everything else (magento, modules..) says "I see this rewrite and it's fine".

I'm ready for the really silly mistake.

2 Answers 2

0

I guess that the alias of the block class of the module you want to rewrite is not AdvancedStock. It might be advancedstock or something else : please check in the config.xml of the module.

Then you will have to write :

    <blocks>
        <digitagri_extendedmdn>
            <class>Digitagri_Extendedmdn_Block</class>
        </digitagri_extendedmdn>
        <the-correct-alias-of-the-block>
            <rewrite>
                <the-correct-path-to-the-block>Digitagri_Extendedmdn_Block_MDN_AdvancedStock_Warehouse_Edit_Form</the-correct-path-to-the-block>
            </rewrite>
        </the-correct-alias-of-the-block>
    </blocks>
7
  • As i've said, i'm already rewriting other blocks from the same module, declared in the same way inside the same <AdvancedStock> tag. I've tried what you suggested but it doesn't work either. Also if this was the case the overwrite wouldn't be showing up at all, but Magento and other modules tell me it's there, which means the config file is properly read. Feb 22, 2018 at 11:21
  • Well, maybe your alias is correct. But you will have to write the path of the rewritten block (what I called the-correct-path-to-the-block) in lowercase. See for example : How to rewrite a block Feb 22, 2018 at 11:28
  • @Narolas if you are sure your code has no mistakes you should check if the same block is not rewritten by any other module
    – Piyush
    Feb 22, 2018 at 11:43
  • @Piyush as i've said, i've checked through a "Extension conflict" module and by dumping the Mage::getConfig()->getNode() info, which shows (for the Warehouse_Edit_Form Block), only 1 rewrite from my module, nothing else. Feb 22, 2018 at 14:01
  • @JulienLoizelet I've tried this and it doesn't work. In fact, the lowercase/uppercase seems dependent on the way things were declared in the original module, because if I use lowercase for my other rewrites of the same module, then they DON'T work. Feb 22, 2018 at 14:14
0

You'll need to declare module dependencies, so your rewrite would work, as you need to ensure MDN_AdvancedStock module is loaded before yours

One example How to use multiple module dependencies

2
  • In this same module I rewrite another block from the same module with the same method, the module dependency is already declared, and it works for the other rewrites. Feb 22, 2018 at 13:58
  • Post your full config.xml better then Feb 22, 2018 at 17:29

Your Answer

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

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