0

My config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Company_Mailchimpextend>
            <version>0.1.0</version>
        </Company_Mailchimpextend>
    </modules>
    <global>
        <helpers>
            <monkey><!-- tried MageMonkey, magemonkey etc. -->
                <rewrite>
                    <data>Company_Mailchimpextend_Helper_Data</data>
                </rewrite>
            </monkey>
        </helpers>
    </global>
</config>

etc/modules/Company_Mailchimpextend.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Company_Mailchimpextend>
            <active>true</active>
            <codePool>local</codePool>
                <depends>
                <Ebizmarts_MageMonkey/>
            </depends>
        </Company_Mailchimpextend>
    </modules>
</config>

Helper/Data.php:

<?php
    class Company_Mailchimpextend_Helper_Data extends Ebizmarts_MageMonkey_Helper_Data {

        private function _setMaps($maps,$customer,$merge_vars, $websiteId)
        {
            Mage::log("test",null,"test.log");

Third party config.xml:

<helpers>
        <monkey>
            <class>Ebizmarts_MageMonkey_Helper</class>
        </monkey>
    </helpers>

It doesn't seem to be extended somewhere else. Cleared cache, the module is showing in config > advance. It still uses the method _setMaps from the third party module.

Thanks!

4
  • 2
    Did you try overriding a not so private method?
    – mam08ixo
    May 26, 2016 at 14:29
  • @mam08ixo ok, thanks, beginners mistake. so it is essentially not possible to overwrite that private method in my module? how should I deal with that because i cannot change the module file, on next update my change could be deleted. May 26, 2016 at 14:36
  • Override the method that invokes the private part.
    – mam08ixo
    May 26, 2016 at 14:59
  • @mam08ixo thanks. if you have time please submit an answer so that I'll accept it. May 26, 2016 at 15:51

1 Answer 1

2

Overriding private methods has no effect, it does not even raise any PHP errors. In order to alter the behaviour of private parent methods you need to override the public or protected method that invokes the private one and change the behaviour there:

<?php
class Base
{
    private function _output()
    {
        return 'foo';
    }

    public function printOutput()
    {
        print $this->_output();
    }

    public function printMyOutput()
    {
        print $this->_output();
    }

    public function printMyOutput2()
    {
        print $this->_output();
    }
}

class Override extends Base
{
    private function _output()
    {
        return 'bar';
    }

    public function printMyOutput()
    {
        print $this->_output();
    }

    public function printMyOutput2()
    {
        print 'bar';
    }
}

$override = new Override();
$override->printOutput();    // prints 'foo'
$override->printMyOutput();  // prints 'bar'
$override->printMyOutput2(); // prints 'bar'

Personally, I would not even re-declare the private method but integrate its logic either directly into the overriden method or, if more complex, move it to a separate model.

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.